我正在将客户端验证 gem 用于即将推出的页面上的表单,无论我做了什么,我都无法让表单显示验证。
这是表格
<%= form_for @user, :remote => true, :validate => true do |f| %>
<% @user.errors.full_messages.each do |msg| %>
<p><%= msg %></p>
<% end %>
<%= f.text_field :username, :placeholder => "Username" %>
<%= f.email_field :email, :placeholder => "Email" %>
<button class="btnSmall" type="submit" name="commit" type="submit" value="Create User"><img src="/assets/arrowWhite.png" alt="Submit Credentials" /></button>
<button class="btnLarge" type="submit" name="submit">Submit<img class="arrowWhite1x" src="/assets/arrowMobileWhite.png" alt="Submit Credentials" /><img class="arrowWhite2x" src="/assets/arrowMobileWhite@2x.png" /><</button>
<% end %>
我正在加载通过 AJAX 发送表单,所以我也在像这样通过 JS 加载验证
$(document).ready ->
$('#new_user').enableClientSideValidations()
这是我的模型
class User < ActiveRecord::Base
attr_accessible :email, :username
validates_uniqueness_of :username, :email
validates :email, :email_format => true
end