I a implementing single table inheritance but am having some trouble with the routing. I have two classes, Gamma and Beta, and both inherit from Alpha. I know that if I want to use Alpha as the controller as opposed to individual controllers for Beta and Gamma, I can follow the instructions here for having a resource default to another controller.
However, what I want to do is have some methods be handled by a central Alpha controller (e.g. edit and update), while other methods be handled by the subclass Beta and Gamma controllers. How can I specify which methods should be pointed to the Alpha controller and which should remain to be handled by Beta and Gamma?
Use inheritance with your controllers. Implement your edit and update functions in an AlphaController
class, and then inherit from that class in you BetaController
and GammaController
classes, where you then implement your other functions.
class AlphaController < ActionController::Base
def edit
...
end
def update
...
end
end
class BetaController < AlphaController
def index
...
end
end
Note that this will make your URLs .../beta/edit and .../beta/update.
You would only want to use the views/alpha/edit.html.erb as a partial view, and then render the alpha view page as a partial in your beta/gamma views.
Remember that even though you are storing the objects in one table Alpha, you still have two classes in your model, Beta and Gamma, and should treat them as such.