【发布时间】:2011-02-05 15:14:47
【问题描述】:
现在我意识到这个话题之前已经讨论过很多次了。但是,似乎没有解决方案希望仅当数据库中的密码为空时才使当前密码字段免除。
我目前有我的用户模型所需的密码,例如:
def password_required?
(authentications.empty? || !password.blank?) && super
end
然后我将更新功能复制到我的注册控制器中:
def update
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated
sign_in resource_name, resource, :bypass => true
redirect_to after_update_path_for(resource)
else
clean_up_passwords(resource)
render_with_scope :edit
end
end
我只是不知道如何确保在编辑空白密码时设备不需要密码,我是否还需要从视图中删除 current_password 字段并执行此操作?
<% if current_user.password_required? %>
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></p>
<% end %>
<p><%= f.submit "Update" %></p>
任何建议都会很好,因为我确信我忽略了一些东西,但我对 Rails 整体还是新手。谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 passwords devise