私のユーザーモデルには
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>
問題は、モデルの特定の属性のみを更新し、毎回パスワードを入力したくないということです。パスワード(および確認)を入力しないと、検証エラーが発生します)
どうすれば状況を修正できますか?