2011-09-18 4 views
0

나는 ruby ​​on signup/signin 시스템에서 일하고있다.가상 속성이 null로 설정되는 이유는 무엇입니까?

나는 가상 속성 (password)을 가진 레일 형태의 루비를 가지고 있습니다. 폼 제출에 대한 응답은 모델 객체를 업데이트하고 저장합니다. before_save : 콜백을 저장하기 전에 encrypt_password 메소드를 호출합니다. 그러나, 나는 가상 속성이 양식에서 가치를 얻고 있다고 생각하지 않습니다.

attr_accessor :password 
attr_accessible :Name, :password, :UserName, :RegistrationName, :BusinessName    

before_save :encrypt_password 

def encrypt_password 
    self.salt = make_salt 
    self.encrypted_password=encrypt(password) 
end 

def make_salt 
    secure_hash("#{Time.now.utc}--#{password}") 
end 

def encrypt(string) 
    secure_hash("#{salt}--#{string}") 
end 

def secure_hash(string) 
    Digest::SHA2.hexdigest(string) 
end 

좋아, 내가 확인하고 예 형태에서 얻은 암호가 null : 나는 그것을 로그인 할 때하는 repeatedly.The 코드가 실패하기 때문이다. 그러나 나는 왜 그런지 이해하지 못한다.

<h1>This is the page of <%= @merchant.Name %> </h1> 

<p>Please enter the password to be used </p> 
<%= random_generator %> 
<%= form_for @merchant,:url=>{:action=>'approve'} do |m| %> 
<%= m.label :Name %><br/> 
<%= m.text_field :Name %><br/> 

<%= m.label :password %><br/> 
<%= m.text_field :password %><br/> 
<%= m.submit "Approve" %> 

<% 엔드 % 내가 직접 그것을 인쇄 할 경우 암호 필드에 입력되고 무엇이든간에 텍스트>

는, 컨트롤러의 승인 작업에서 볼 수 있습니다 :이 양식에 대한 코드입니다 params [: merchant] [: password]를 입력하십시오.

instance.password 

당신이 그것을 관련 찾아보고있는 일부 debugger 라인을 넣어 :하지만 모델에 어떤 attr_accessor 같은

답변

1

null의 경우, 당신은과 그것의 가치를 얻을 수 있습니다.

관련 문제