Reputation: 1317
How can I pass the action a user is taking to a method within my controller?
For example:
before_action :require_login, only: [:new, :create, :edit, :update, :destroy]
If the user tries to use the :edit action before logging in in my method I would like to say something like this:
def require_login
unless current_user
if (:edit action)
flash[:alert] = "You must log in before you are able to edit foo"
end
end
end
Upvotes: 1
Views: 32
Reputation: 14048
is params[:action]
what you're after?
flash[:alert] = "You must log in before you are able to #{params[:action]} foo"
params[:controller]
should be available too
Upvotes: 1