客户端验证和Rails4 [英] Client Side Validations and Rails4
问题描述
我使用以下宝石使用新分支将rails4的客户端验证集成在一起
I integrated client side validations with rails4 using the new branches available using the following gems
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"
我还添加了以下所需的JavaScript
I also added the required JavaScript as the following
//= require jquery
//= require jquery_ujs
//= require foundation
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .
//= require_self
我创建了这个测试表单以查看它是否有效
I created this test form in order to see if it works
= simple_form_for(@post, :validate => true) do |f|
= f.error_notification
.form-inputs
= f.input :title, :required => true
.form-actions
= f.button :submit
当然在模型中,它是
validates :title, presence: true
问题是我无法弄清楚它为什么不起作用,而JavaScript控制台显示以下错误:
The problem is I can't figure our why it is not working, while JavaScript Console shows the following error:
Uncaught TypeError: Cannot read property 'add' of undefined
推荐答案
这些宝石涉及很多配置和顺序。我没有解释整个过程,而是可以在SO中为您提供类似问题的解决方案。请查看并按照相同的方式进行操作。
These gems involve a lot of configurations and ordering to be proper. Instead of explaining the whole procedure i can give you a link in SO where a similar problem was solved. Please do check it out and follow the same.
ruby-on-rails client_side_validation simple_form javascript error
希望它有所帮助!
这篇关于客户端验证和Rails4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!