无法使用client_side_validations提交表单

时间:2013-08-21 09:40:20

标签: ruby-on-rails ruby forms validation

我正在使用client_side_validations以连续方式显示验证。这些验证有效但当我点击“提交”时,没有任何反应。

这是我的代码:

<%= form_for @user, :validate => true do |f| %>
....
<%= f.submit "Inscription" %>
<% end %>

client_side_validations.rb

# ClientSideValidations Initializer

# Uncomment to disable uniqueness validator, possible security issue
# ClientSideValidations::Config.disabled_validators = [:uniqueness]

# Uncomment to validate number format with current I18n locale
# ClientSideValidations::Config.number_format_with_locale = true

# Uncomment the following block if you want each input field to have the validation messages attached.

# Note: client_side_validation requires the error to be encapsulated within
# <label for="#{instance.send(:tag_id)}" class="message"></label>

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  unless html_tag =~ /^<label/
    %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
  else
    %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
  end
end

我还在我的application.js

中添加了//= require rails.validations

提前谢谢!

0 个答案:

没有答案