Ive에 다음과 같은 문제가 있습니다. 나는 activated라는 컬럼을 가진 user라는 모델을 가지고있다. 나는 그 값을 업데이트하려고 시도했지만, 오류가 발생했습니다 : 유효성 검사 실패 : 암호는 비워 둘 수 없습니다. 암호는 너무 짧습니다 (최소 6 자). 감동하지 않으므로 나에게 의미가 없습니다. 암호 필드! 활성화 된 열을 업데이트하려고합니다. 내가 여기에 해당 코드를 넣는다면,하지만 더 많이 묻는 것이 필요하다고 생각한다면 :) 미리 감사드립니다.Rails update_attribute
모델 :이 방법은 활성화되는
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation, :activated
has_many :sucu_votes
email_regex = /\A[\w+\-.][email protected][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
컨트롤러? 먼저 루비 규칙 만이 아니라 더 레코드를 업데이트 등의 작업을 수행 할 true 또는 false를 반환하는 조건 방법을 사용하는 것입니다,
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
매우 감사 기록을 위해 콜백의 나머지를 건너한다! 나는 그것을 실제로 이전에 좋아했지만, 다른 이유로 일하지 못했습니다. 그러나 그 모든 지금 ok :) – gumlym