Right now, I have two views that are using the users#create action: users/new.thml.erb and enter_email.html.erb.
The problem is that with the current code, the user is redirected to new.html.erb when the
form in enter_email.html.erb has a validation error. So I tried this:
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
if params[:action] == "enter_email"
render 'enter_email'
else
render 'new'
end
end
end
I wanted to user to be redirected to enter_email.html.erb when the action is ‘enter_email’. But I’m still being redirected to ‘new.html.erb’.
Any suggestions to fix this? (it is because the action being performed is actually create? If so, how to modify the code to make the redirection work?)
I see a couple of ways to do it:
Add a hidden field to both forms, and check in
paramsfor the value of that field, so you know which form you come fromhidden_field_tag ‘form_name’, ‘enter_email’
Use a different action for creation, like
create_from_enter_email, and direct theenter_emailform to it.