validates_confirmation_of :password
ユーザーモデルにがあります。問題は@comment.user.save!
、ユーザーアカウントの一部の属性を更新するためにコメントが作成されたときにも実行されることです。
コメントを作成するときにエラーが発生しますValidation failed: Password confirmation can't be blank
。コントローラが保存関数も呼び出している:on => "save"
ため、検証に追加できません。comments
このスレッドのRailsモデルの検証は作成と更新についてのみ読んだことがありますが、特定の問題には答えられません。
UPDATE ユーザーモデルスニペット:
class User < ActiveRecord::Base
attr_accessor :password
# validations
validates_presence_of :username
validates_length_of :username, :within => 6..25
validates_uniqueness_of :username
validates_presence_of :email
validates_length_of :email, :maximum => 100
validates_format_of :email, :with => EMAIL_REGEX
validates_confirmation_of :password, :if => :password_changed?
validates_presence_of :password_confirmation
validates_length_of :password, :within => 4..25, :on => :create
before_save :create_hashed_password
after_save :clear_password
private
def clear_password
self.password = nil
end
end