【发布时间】:2016-04-20 21:53:41
【问题描述】:
我有一个相当长的用户注册表单,并希望找到一种方法来在出错后保留表单值。我遇到了类似的question,但答案似乎不起作用,可能是因为它来自 2010 年。有什么简单的方法可以做到这一点吗?这是我的相关控制器代码(主要是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
【问题讨论】:
标签: ruby-on-rails forms ruby-on-rails-4 devise