2014-09-03 68 views
0

我正在運行驗證條款的服務與布爾複選框在設計的軌道4,我看到PARAMS被傳遞,但我的驗證仍然會拋出一個錯誤。布爾驗證沒有通過,但參數是存在Rails 4和設計

html.erb

<%= check_box_tag(:agree) %> 
<%= label_tag(:agree, "I Agree") %> 

devise_permitted_pa​​rameters.rb

def configure_permitted_parameters 
    devise_parameter_sanitizer.for(:sign_up) << :first_name << :last_name << :agree 
    devise_parameter_sanitizer.for(:account_update) << :first_name << :last_name 
end 

如果我這樣做模型它不工作:

validates_acceptance_of :agree, :allow_nil => false, :accept => true, :on => :create 

服務器:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"VfMsm8nigtdMDh/jo6SyU8mUt5LIWlz0ymuiJwl4qFY=", 
"user"=>{"first_name"=>"c", "last_name"=>"c", "email"=>"[email protected]", "password"=>"[FILTERED]", 
"password_confirmation"=>"[FILTERED]"}, "agree"=>"1", "commit"=>"Register"} 
Unpermitted parameters: first_name, last_name 

不知道爲什麼我有不允許的參數......只有當我提交提交表單時纔會出現。

它通過,如果我使用從其他職位這項建議,但它也允許註冊,如果同意框未選中:

validates_inclusion_of :agree, :in => [true, false] 

回答

0

通過我意識到的form_for使用所以這就是爲什麼代碼看後的form_tag語法沒有按預期工作。它也顯示了爲什麼它仍然輸出提交的信息。

我仍然不是100%確定爲什麼有不允許名字和姓氏的參數。我認爲這是一個解決各種問題的cookie問題,如果你重新啓動服務器,它再次罰款。

希望這可以節省別人在未來的時間。