SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails: controller/module confusion

    I understand that I can use modules to create URLs like:
    Code:
    http://example.com/secure/products/edit/1
    ... where the controller is Secure::ProductsController (app > controllers > secure > products_controller.rb) and edit is an action of this controller.

    Here's where I'm confused: I want to create an authentication system where each Secure::FooController (so, any controller within the "secure" folder) has a before_filter :authourize attached to it. If authourization fails, the user should be sent to
    Code:
    http://example.com/secure/signin
    ... where the controller is SecureController (note, NOT Secure::SigninController - so something like app > controllers > secure_controller.rb) and signin is an action. So, my question is, what should the structure of my app look like? Every time I've tried to build something like the above I get unknown action routing errors: controllers > secure_controller.rb and controllers > secure > foo_controller.rb don't play nicely with each other. Why?

    In the example above, should signin be a controller instead of an action (ie. Secure::Signin, so controllers > secure > signin_controller.rb)? Any advice/help appreciated...

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is up to how you perceive your application, but you can add an :except => "signin"
    clause to your before filter and put signin as an action of the secure controller.

    Alternatively the signin action can be part of the default controller and redirect to the secure one. I prefer the first way, but I definitely wouldn't give a sign in its own controller.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •