Ruby on Rails 3上的jQuery Validator插件?

目前我想知道为什么jqueryvalidation器不能在ruby on rails上使用以下代码? 我注意到它适用于text_field标签但不适用于f.text_field有没有人知道如何使它与f.text_field一起使用? 谢谢

文档就绪function

$("#user_signup_form").validate({ rules: { user_username:{ required: true, minlength: 3 }, user_email:{ required: true, email: true }, user_password:{ required: true, minlength: 7 }, user_password_confirmation:{ required: true, minlength: 7, equalTo: "#user_password" } }, messages: { user_username:{ required: "Required", minlength: "Min Length is 3 characters" }, user_email:{ required: "Required", email: "A valid email address is required" }, user_password:{ required: "Required", minlength: "Min Length is 7 characters" }, user_password_confirmation:{ required: "Required", minlength: "Min Length is 7 characters", equalTo: "New Password Doesn't Match" } } }); {:id => "user_signup_form"}) do |f| %>  

prohibited this user from being saved:





您需要对字段名称而不是id进行validation。 就像我在下面所做的那样。 首先包括必需的jquery库。

 <%= javascript_include_tag "jquery-1.6.2.min.js" %> <%= javascript_include_tag "jquery.validate.js" %> <%= form_for(:user, url => signup_path, :html =>{:id => "user_signup_form"}) do |f| %> <% if @user.errors.any? %> 

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

    <% @user.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%= f.label :username, "Select a username for tingle" %>
<%= f.text_field :username %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password, "Select a password for tingle" %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm password" %>
<%= f.password_field :password_confirmation %>
<%= f.submit defined?(@button_label) ? @button_label : "Signup" %>
<% end %>