我使用路径 assets\javascripts\jquery.validate.js (rails 3.2) 上的 jquery 插件进行客户端验证。但它不起作用。我的表格:
update_name_phone_city_user_registration_path, :html => { :id => "form_edit_name", :method => :put }, :remote => true) 做 |f| %>10 %> “提交” %>
我的 application.js 文件:
//= require jquery
//= require jquery_ujs
//= require bootstrap-modal
//= require_tree .
$(document).ready(function() {
$("#form_edit_name").validate({
debug: true,
rules: {
"user[name]": {
required: true,
minlength: 2
},
"user[name]": {
required: 'Your username is required',
minlength: 'The minimum number of characters is 2'
}
alert("ok");
});
});
怎么了?
UPD 1 生成的 HTML- 代码
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.validate.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<form accept-charset="UTF-8" action="/users" class="edit_user" id="form_edit_name" method="post">
<div><label for="user_name">Name</label><br />
<input id="user_name" name="user[name]" size="30" type="text" value="" /></div>
</form>