I've included controllers in a gem I wrote some time back.
One of the main reasons for using the namespace is because your entire gem should be under the duress of a single module:
#lib/exception_handler.rb
module ExceptionHandler
#Exception Handler
class Exceptions < Rails::Engine
This means that if you're calling a controller from within the gem (which is meant to be self-contained), you'll generally have to invoke it inside the module:
ExceptionHandler::ExceptionController.action(:show).call(env) }
--
In the sense of Devise, it makes sense for them to include their controllers in a namespace for two reasons:
- It permits them to call their controllers from within their module
- They are able to include the controllers without the need of external dependencies
which is called when I get "users/sign_up"
The devise controllers can be broken down by the routes Devise sets:
new_user_session GET /users/sign_in {controller:"devise/sessions", action:"new"}
user_session POST /users/sign_in {controller:"devise/sessions", action:"create"}
destroy_user_session DELETE /users/sign_out {controller:"devise/sessions", action:"destroy"}
These are just routes for the sessions
controller (which handles login etc).
There are other routes including registrations
etc.
The key here is to understand that Devise has to work "out of the box" -- otherwise most people wouldn't use it. It achieves this by self-containing its controllers, ensuring that, as sanfor
recommended, they are not conflicted.
If you have more specific requests, I'll gladly answer them for you.