Ruby on Rails: How do you do HTTP auth over multiple controllers?
Posted
by
DerNalia
on Stack Overflow
See other posts from Stack Overflow
or by DerNalia
Published on 2010-12-27T02:19:00Z
Indexed on
2010/12/27
2:54 UTC
Read the original article
Hit count: 241
ruby-on-rails
So, Here are the relevant routes
map.namespace "admin" do |admin|
admin.root :controller => :site_prefs, :action => :index
admin.resources :site_prefs
admin.resources :link_pages
admin.resources :menu_bars
admin.resources :services
admin.resources :users
end
And I have this for one controller:
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "1234" && password == "1234"
end
end
How do I set up my admin controllers to authenticate no matter what page within any of those controllers is navigated to, yet only have it authenticate once among all the admin controllers, and have the code all in one spot.
Right now, the only I can think of to authenticate is to copy the auth code into each controller, and I hate having duplicate code... so.... yeah
© Stack Overflow or respective owner