views:

232

answers:

3

Hi, I have a special url which I would want only few people to have access to. I have a list of super users stored as an array in the app.yml. How can I use this array in :requirements section of a specific route in the routes.rb file to allow only those super users access to this route? Thanks a lot.

+3  A: 

No, you can't. :requirements are related to route parameters only.

Which is, in my opinion, a good thing. It's a well known convention to have authentication logic in controllers.

Pedro
+3  A: 

Like Pedro said.. authentication logic should be in controller code.
Take a look at before_filters, where you specify methods that will be called before (all or specified) actions in a controller are run. You can use such a method to deny actions from running. Look for the section named Filter Chain Halting here

:requirements is for specifying constraints for parts of the URL for the route to match. Usually regular expressions are specified as shown here.

map.geocode 'geocode/:postalcode', :controller => 'geocode',
              :action => 'show', :requirements => { :postalcode => /\d{5}(-\d{4})?/ }
Gishu
A: 

Thats what I thought, thanks anyway guys.

Swamy g