次の問題が発生しました。アクティベートされたという名前の列を持つuserというモデルがあります。メソッドをアクティブにしてその値を更新しようとしていますが、エラーが発生します:検証に失敗しました:パスワードを空白にすることはできません、パスワードが短すぎます(最小6文字)これは私には意味がありません。パスワードフィールド!アクティブ化された列を更新したいだけです。ここにコードを入れますが、関連性があると思いますが、もっと必要だと思われる場合は、質問してください:)よろしくお願いします!
モデル:
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation, :activated
has_many :sucu_votes
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => {:with => email_regex},
:uniqueness => { :case_sensitive => false }
validates :password, :presence => true,
:length => { :within => 6..15 },
:confirmation => true
before_save :encrypt_password
def activated?
self.update_attributes!(:activated => true)
return self.activated
end
メソッドがアクティブ化されたコントローラー?と呼ばれる
def activate
if request.get?
user=User.find_by_id(params[:id])
if user.activated?
flash[:notice]="Your account has been activated"
#redirect_to :controller => 'sessions', :action => 'new'
else
flash[:error]="We couldnt activate the account"
redirect_to :controller => 'sessions', :action => 'new'
end
end
end