У меня довольно длинная форма регистрации пользователя, и я надеялся найти способ сохранить значения формы после ошибки. Я столкнулся с аналогичным question, но ответ, похоже, не работает, возможно, потому, что он с 2010 года. Есть ли какой-либо простой способ сделать это? Вот мой Релевент код контроллера (в основном Devise
):Rails 4 + 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
Да, заполненные поля находятся в 'sign_up_params'. Как я могу использовать их для заполнения полей? –