我的用户模型具有轨update_attributes方法
validates :password, :presence => true,
:confirmation => true,
:length => {:within => 6..40}
和用户的控制器上我的更新动作
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
end
我编辑的看法是
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => @user.errors%>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %> <br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %> <br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
的问题是,我只想更新模型的特定属性,而不是输入密码每次。如果我没有输入密码(和确认),我会得到验证错误)
如何解决这种情况?
我刚刚看到http://stackoverflow.com/questions/7073720/ruby-on-rails-tutorial-how-to-edit-user-information-without-confirming-the-pass我会测试它并回报 – 2012-01-07 10:29:49
链接上的解决方案不工作... – 2012-01-07 16:42:39