Wes Gamble
2006-May-25 21:51 UTC
[Rails] Setting a global before_filter action in application.rb
Can you set a global before_filter action in application.rb? So, for example, you could control authentication for all of the controllers in an app.? Obviously, you would need a way to reference actions by controller within this "global before-filter". Thanks, Wes -- Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-May-25 22:08 UTC
[Rails] Re: Setting a global before_filter action in application.rb
Wes Gamble wrote:> Can you set a global before_filter action in application.rb? > > So, for example, you could control authentication for all of the > controllers in an app.? > > Obviously, you would need a way to reference actions by controller > within this "global before-filter". > > Thanks, > WesGot it!!! Wow, that was really easy. If anyone''s interested in the general case of the Authenticate recipe, so that you can apply it to all of your app''s controllers, I have a way to do it. Wes -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-May-25 22:24 UTC
[Rails] Setting a global before_filter action in application.rb
On May 25, 2006, at 2:51 PM, Wes Gamble wrote:> Can you set a global before_filter action in application.rb? > > So, for example, you could control authentication for all of the > controllers in an app.? > > Obviously, you would need a way to reference actions by controller > within this "global before-filter". > > Thanks, > Wes > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsWes- Yeah you can put global before_filter in application.rb. thats what its there for. All your other controllers inherit from this one. Just set it up like you would think. Then if you want to overide it in individual controllers you use this syntax in a normal controller: class ApplicationController < ActionController::Base before_filter :authenticate_user protected def authenticate_user # authentication code here end end class FooController < ActionController skip_before_filter :authenticate_user, :only => [:index, :list, :show] #rest of controller end -Ezra
Wes Gamble
2006-May-25 22:34 UTC
[Rails] Re: Setting a global before_filter action in application.rb
Wes Gamble wrote:> Wes Gamble wrote: >> Can you set a global before_filter action in application.rb? >> >> So, for example, you could control authentication for all of the >> controllers in an app.? >> >> Obviously, you would need a way to reference actions by controller >> within this "global before-filter". >> >> Thanks, >> Wes > > Got it!!! > > Wow, that was really easy. > > If anyone''s interested in the general case of the Authenticate recipe, > so that you can apply it to all of your app''s controllers, I have a way > to do it. > > WesI spoke too soon. My error scenarios fail looking for the generic stuff in the specific places. -- Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-May-25 22:36 UTC
[Rails] Re: Setting a global before_filter action in application.rb
Ezra Zygmuntowicz wrote:> On May 25, 2006, at 2:51 PM, Wes Gamble wrote: > >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > Wes- > > Yeah you can put global before_filter in application.rb. thats what > its there for. All your other controllers inherit from this one. Just > set it up like you would think. Then if you want to overide it in > individual controllers you use this syntax in a normal controller: > > class ApplicationController < ActionController::Base > before_filter :authenticate_user > > protected > > def authenticate_user > # authentication code here > end > > end > > > > class FooController < ActionController > > skip_before_filter :authenticate_user, :only => > [:index, :list, :show] > > #rest of controller > > end > > > -EzraWhat about redirecting to templates? I put a common login page in ''common/login_form.rhtml'' (common is my directory under views). But when the actions fail, they''re trying to find a login_form template underneath their specific view folders. Wes -- Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-May-25 22:44 UTC
[Rails] Re: Setting a global before_filter action in application.rb
> > > What about redirecting to templates? I put a common login page in > ''common/login_form.rhtml'' (common is my directory under views). > > But when the actions fail, they''re trying to find a login_form template > underneath their specific view folders. > > WesOK now I really got it. I was rendering when I should have been redirecting. Still - a lot of fun! wg -- Posted via http://www.ruby-forum.com/.