Reputation: 4065
I have a model called User
. In the model I want to check if a value is true or false.
If the value is true then break all operations and redirect to a specific page.
How do I do that?
before_create :check_user
def check_user
if User.find_by_email(self.email)
redirect_to root_path
end
end
Upvotes: 0
Views: 1100
Reputation: 83680
You can't and you never need to redirect form model.
You should do it in controller something like
before_filter :check_user
...
private
def check_user
redirect_to root_path unless User.find_by_email(params[:user][:email])
end
Upvotes: 2
Reputation: 9691
before_create :check_user
def check_user
unless User.find_by_email(email).nil?
redirect_to root_path
end
end
See if this does what you want.
Upvotes: 0