Reputation: 1129
After a failed validation I would like the user's brower to display the /new action in the URL not the /create action (which replaces /new after every failed validation). Any way to do this with rails?
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to success_path
else
render 'new'
end
end
Upvotes: 0
Views: 57
Reputation: 4578
You could do it with a redirect using the session instead:
def new
if session[:new_user_params].present?
@user = User.new(session[:new_user_params])
@user.valid?
else
@user = User.new
end
end
def create
@user = User.new(params[:user])
if @user.save
session.delete(:new_user_params)
redirect_to success_path
else
session[:new_user_params] = params[:user]
redirect_to action: :new
end
end
Upvotes: 2