我已经覆盖了注册控制器for Devise,更确切地说是 #create 操作,我直接从Repo中获取了代码:
def create
build_resource(sign_up_params)
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
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}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else #what code do I need here to preserve user entered field(s)?
clean_up_passwords resource
respond_with resource
end
end
对于资源(用户)有效并保存的情况,它一切正常,但当用户无效时,它会重定向回到看来,问题是它没有保留用户已输入的字段。
示例:
注册#new 查看,我输入用户信息,
提交和验证失败和重定向后,用户输入未被保留....
如何让Devise在注册#create 覆盖中保留用户输入的字段?
提前致谢!