我一直在学习 Michael Hartl 的 Ruby on Rails 教程。目前,为了编辑任何用户属性,用户必须确认其密码。有没有什么方法可以更新用户属性而不必这样做?
我的表格如下所示:
<%= form_for @user do |f| %>
<div class="field">
<%= f.label :course1 %><br />
<%= f.text_field :course1 %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>"
我在 users_controller.rb 中的更新定义如下所示:
def update
if @user.update_attributes(params[:user])
flash[:success] = "Edit Successful."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
end
目前,update_attributes 操作失败。
Thanks!
为了稍微完善迪伦的答案,您需要定义那个给您错误的password_changed方法。我使用了不同的名称,因为我不在乎密码是否已更改。
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 },
:unless => :already_has_password?
private
def already_has_password?
!self.encrypted_password.blank?
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)