Reputation: 305
I am using devise invitable in my application for inviting the users. If the user exists in the database I have to redirect him to signin screen otherwise to the signup screen if he is a new user. Even if I invite the user like:
User.invite!(:email => "[email protected]", :name => "Jonny")
, the data is getting entered in the database, then the user is always getting redirected to sign in screen. I had written the following for checking the email in invitations controller:
def edit
if User.exists?(:email => params[:email])
redirect_to new_user_session_path
else
redirect_to new_user_registration_path
end
end
Can some help me how I can handle this situation.
Upvotes: 1
Views: 811
Reputation: 1051
For edit it should find a user by id rather than going on to the new_user_session_path. The edit method should contain the following piece of code.
def edit
if User.exists?
@user = User.find(params[:id])
else
redirect_to new_user_registration_path
end
end
Upvotes: 1