Josh S. wrote:
Controller inheritance works fine, and is a good way to share code
related controllers. For instance, putting your user authentication
filter in a superclass controller so all the subclasses are
I took some time to realize it. In fact if I were in a more traditional
framework (that is to say one where I had to write a lot more code), I’d
probably used inheritance from the beginning.
Rails is new to me, and I try to do things in “the right way”. So I
didn’t think to inheritance, since I hadn’t seen it. But actually it
seems a widespread tecnique.
The only major caveat I’ve seen is that if you inherit an action from
superclass controller that renders a view, you have to create a view
template for it in the subclass controller too, since
only looks for the view template in the class of the controller
instance, not by searching the views of the superclasses.
I noticed it. I think I’ll have something like
| Post |
| Controller |
| Admin::Post| | Pub::Post |
| Controller | | Controller |
where the views exist only for the subclasses (along with the layouts)
and PostController has only some partials.
blog: http://www.akropolix.net/rik0/blogs |
site: http://www.akropolix.net/rik0/ |
forum: http://www.akropolix.net/forum/ |