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.
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
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.
Wes
I spoke too soon. My error scenarios fail looking for the generic stuff
in the specific places.
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
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.