I have a rather long user registration form and was hoping to find a way to retain form values after an error. I came across a similar question, but the answer does not seem to work, perhaps because its from 2010. Is there any simple way to accomplish this? Here's my relevent controller code (mostly Devise):
def create
if params[:user] && !params[:user][:password]
params[:user][:password] = "testpassword"
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
# I believe this is where errors are handled
clean_up_passwords resource
set_minimum_password_length
respond_with resource
# render :action => "new" I tried adding this line instead of the line above with no success
end
else
super
end
end
Your params are passing to the view when you render. so, something like this:
f.email_field :email, value: params.include?(:user)? params[:user][:email] : ""
should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With