2013-07-14 123 views
3

我使用所提供的新的分支使用下面的寶石客戶端驗證和Rails4

gem 'simple_form', '~> 3.0.0.rc' 
gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta" 
gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git' 
gem "jquery-rails" 

集成客戶端驗證與rails4我還添加了必需的JavaScript作爲以下

//= require jquery 
//= require jquery_ujs 
//= require foundation 
//= require rails.validations 
//= require rails.validations.simple_form 
//= require_tree . 
//= require_self 

我創造了這個測試表格以便看它是否有效

= simple_form_for(@post, :validate => true) do |f| 
    = f.error_notification 

    .form-inputs 
    = f.input :title, :required => true 

    .form-actions 
    = f.button :submit 

當然在模型中,我T爲

validates :title, presence: true 

問題是我不明白我們爲什麼它不工作,而JavaScript控制檯顯示以下錯誤:

Uncaught TypeError: Cannot read property 'add' of undefined 

回答

0

的問題似乎是在JavaScript的順序,只是改變它會正常工作的順序