2 before_filters, only want one to render something

I have two before_filters for a few of my controllers. They are running
my own methods authorize and admin_authorize. authorize is called on
just about every action to make sure that a user is logged in.
admin_authorize is called on about 80% of the actions and is used to
make sure that a user is an administrator. If a user tries to access an
admin_authorize protected action without being logged in then both
authorize and admin_authorize trigger and both have redirects in them.
This if course makes rails complain about two renders when only one is
allowed. Is there a way that I can make authorize skip
admin_authorize? Or will I have to go through and pick only one method
to be before_filtered for each action?

def authorize #inspired by rails recipes
unless session[:user]
flash[:notice] = “Please log in”
session[:intended_action] = action_name
session[:intended_controller] = controller_name
session[:intended_id] = params[:id] || nil
redirect_to(:controller => “account”, :action => “login”)
return
end
end

def admin_authorize
unless session[:user] && User.find(session[:user]).admin?
redirect_to :controller=> “groups”, :action => “index”
end
end

Thank you,
Matthew M.
blog.mattmargolis.net

On 2-jul-2006, at 16:40, Matthew M. wrote:

through and pick only one method to be before_filtered for each
action?

Return false from a filter method to halt the filter chain execution.


Julian ‘Julik’ Tarkhanov
please send all personal mail to
me at julik.nl

before_filter :authorize, :only => [:action1, :action2]
before_filter :auth_admin, :except => [:action1, :action2]

Matthew M. wrote:

I have two before_filters for a few of my controllers. They are running
my own methods authorize and admin_authorize. authorize is called on
just about every action to make sure that a user is logged in.
admin_authorize is called on about 80% of the actions and is used to
make sure that a user is an administrator. If a user tries to access an
admin_authorize protected action without being logged in then both
authorize and admin_authorize trigger and both have redirects in them.
This if course makes rails complain about two renders when only one is
allowed. Is there a way that I can make authorize skip
admin_authorize? Or will I have to go through and pick only one method
to be before_filtered for each action?

Julian ‘Julik’ Tarkhanov wrote:

redirects in them. This if course makes rails complain about two


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Perfect. Thank you.

Matthew M.
blog.mattmargolis.net

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs