Я использую Rails -3.2.1.В одной из моих форм я использую валидацию jquery.Моя форма ниже
new_account.html.erb
<%= form_for(@account, :url =>{:action=> "create_account"}) do |f| %>
<table width="80%" border="1" align="center" cellpadding="5" cellspacing="5">
<tr>
<td width="30%">
<%= f.label :Account_Name, :class => :style1_bold %>
</td>
<td>
<%= f.text_field :account_name, :class => "input_border required ONLY_ALPHABET" %>
</td>
</tr>
<tr>
<td>
</td>
<td>
</div>
<div class="actions">
<%=f.submit "Add Account" %>
<%= link_to "Cancel", home_path, :class=>"style2_link" %>
</div>
</td>
</tr>
</table>
<% end %>
В приложении. Js
//= require jquery
//= require jquery_ujs
// require_tree .
//= require_directory .
jQuery.noConflict();
jQuery(document).ready(function(){
/////////////////////////////////////////////
//// Validatior for only alphabet
/////////////////////////////////////////////
jQuery.validator.addMethod("ONLY_ALPHABET",function(value,element){
return this.optional(element) || /^[a-zA-Z ]+$/.test(value);
},"Only Alphabet is allowed");
/////////////////////////////////////////////
//// Validation for Create Account
/////////////////////////////////////////////
jQuery("#new_account").validate(
{
rules: {
account_account_name: {
required: true,
ONLY_ALPHABET: true,
maxlength: 30
}
},
messages: {
account_account_name: {
required: "Please fill category",
ONLY_ALPHABET: "Only Alphabet is allowed",
maxlength: "Not more than 30 characters"
}
}
});
});
В форме отправки.Он не показывает мое сообщение, а показывает сообщения по умолчанию в jquery.
Я включаю этот файл jquery.validate.min.js