I’d like to force a user to change their password on login (assuming they’ve got a certain boolean marker set to true).
Right now I’m trying to do it via a before_filter called change_password_check that’s in ApplicationController.
def change_password_check
if current_user.change_password == true
flash[:notice] = "You must be update your password before continuing"
redirect_to change_password_path
return false
end
end
The problem, obviously, is that I get a redirect loop.
So, how can I only do that before_filter if the user is NOT on the change_password_check route (or posting to user#update)?
I’m running Rails 3.
You can specify only and except as options to the before_filter. These accept an array of arguments, in the above case, you only have one method you wish to skip, however if you had another method that was to be skipped (your update action), you can do:
Only is the opposite of except, so:
Would only be run if the method is check_me.