ruby-on-rails – 如何从设计表单中分离更改密码
我想做两件事:
1)更改默认的“编辑用户表单” – 随设备提供 – 删除“密码”并允许更新其他字段而无需输入密码,即删除密码的默认验证. 2)创建一个单独的表单来更改密码 我有一切工作,只有一个问题,在更新密码的单独表格中,我已经包含了当前密码的字段.使用表单时,没有对当前密码进行验证,所以我改变了 @user.update_attributes(params[:user]) 至 @user.update_with_password(params[:user]) 这有效,但它提出了另一个问题.返回主表单中除了密码之外的所有其他详细信息,表单现在要求输入“当前密码”.如果没有验证主表单上调用的当前密码,我怎样才能实现这一目标? 这是我的注册控制器: def update @user = User.find(current_user.id) if @user.update_attributes(params[:user]) set_flash_message :notice,:updated # Sign in the user bypassing validation in case his password changed sign_in @user,:bypass => true redirect_to after_update_path_for(@user) else clean_up_passwords(resource) respond_with_navigational(resource) do if params[:change_password] # or flash[:change_password] render :change_password else render :edit end end end end 谢谢! 解决方案1 我找到了问题的解决方案(尽管非常混乱): def update @user = User.find(current_user.id) if params[:user][:password].blank? if @user.update_attributes(params[:user]) set_flash_message :notice,:updated # Sign in the user bypassing validation in case his password changed sign_in @user,:bypass => true redirect_to after_update_path_for(@user) else respond_with_navigational(resource) do render :edit end end else if @user.update_with_password(params[:user]) set_flash_message :notice,:bypass => true redirect_to after_update_path_for(@user) else clean_up_passwords(resource) respond_with_navigational(resource) do render :change_password end end end 解决方案2 你能建议更好的解决方案吗? 解决方法
你有兴趣查看Devise wiki吗?这两种情况都有例子
> https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password 您应该查看@ user.update_with_password(params [:user])vs @ user.update_attributes(params [:user]) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 我在哪里可以找到我的mac中的sqlite3数据库文件?
- c# – 从ASP.NET webservice调用有状态的非托管C
- c – Eclipse SDL构建错误:“启动配置中指定的程
- XML基础编程解析(DOM SAX Dom4J)
- 反向Ajax,第4部分:Atmosphere和CometD
- C#任务并行库和NHibernate / Spring.NET
- SQLite的局限性
- Oracle SQL Developer:如何从ref cursor查看结果
- Keil ULINK2 Flash Download failed-ARM7TDMI
- ruby-on-rails – 如何在Rails中实现rufus-sched