0
我正在使用軌道註冊/登錄系統上的紅寶石。爲什麼虛擬屬性被設置爲空?
我有一個紅寶石的軌道形式有一個虛擬屬性 - 密碼。響應表單提交的動作會更新模型對象並將其保存。保存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
好吧,我檢查並且是從表單中獲得的密碼爲空。但我不明白爲什麼。這是形式的代碼:
<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 [:商家] [:密碼]。但在模型中它是空