I am aware that controllers can be placed in modules:
ruby script/generate controller modulename/controllername
But what does this buy me? Is it just a way of ensuring that my source
code is nicely arranged, or can I use the fact that a set of controllers
are all within a particular model to implement functionality common to
all of those controllers?
Why am I asking?
The app we’re currently working on has some controllers which can be
accessed by anyone and some which require the user to login before they
can access it. Currently we have
at the top of each “secure” controller. I would like to separate secure
controllers into one module and unsecure controllers in another. I
thought that this might give me a way to DRY the code up - by having the
secure module enforce the login requirement. But if there is a way to
achieve this, it’s escaping me.
I can obviously achieve the desired effect through inheritance, as
But this requires me to remember to change the base class of each new
secure controller (and raises the spectre of having a controller in the
secure module which doesn’t inherit from the appropriate base).
Am I missing something?