我似乎無法找出原因,這種比較是不工作:簡單的字符串比較不起作用!隨之而來的挫折
if params[:password].to_s == params[:conf_password].to_s
#do something
else
#do something else
結果總是假,那麼執行else塊...任何人都知道爲什麼嗎?
編輯:檢查輸出顯示兩個參數是相同的。使用來自password_field_tag的「form_for」和「conf_password」來收集「密碼」。
如果「conf_password」被包括在「的form_for」一個沒有這樣的方法引發錯誤,因爲在模型中沒有列conf_password。也許有收集這個參數的更好方法,可以解決這個問題。
關於PARAMS一些日誌輸出。
PARAMS: {"password"=>"1234567", "company"=>"company1", "companykey"=>"ckey2"}, "conf_password"=>"1234567",
代碼來獲取這些值
<tr> <td> <%= label_tag(:password, "Password") %> </td> <td> <%= f.password_field :password %> </td> </tr>
<tr> <td> <%= label_tag(:conf_password, "Confirm Password") %> </td> <td> <%= password_field_tag(:conf_password) %> </td> </tr>
如何:基於扣除不是知識
更多儘管從描述看API
未經測試的例子形式的基礎上覆制粘貼編碼
未經測試的例子控制器向我們展示這兩個值實際上是什麼? – 2011-02-27 04:55:20
你已經創建了輸出兩個'PARAMS [:密碼]'和'PARAMS [:conf_password]'不只是一般的PARAMS?從laymans的角度來看,密碼似乎在一個散列內,不應該被訪問相同:conf_password – 2011-02-27 05:04:38
我怎樣才能輸出?我不熟悉Rails.logger。它在一個創建方法中,所以沒有相關的視圖來這樣做。我目前正在這樣做:Rails.logger.debug(「PARAMS:#{params.inspect}」)。我還沒有散列密碼(除非我自動完成)。一旦我解決了這個錯誤,我將該代碼放入模型中。 – reader1 2011-02-27 05:06:09