【问题标题】:Ruby on Rails 3.0 JQuery Validation RemoteRuby on Rails 3.0 JQuery 验证远程
【发布时间】:2011-11-17 21:34:46
【问题描述】:

我正在使用 JQuery Validation 插件来验证我网站上的注册表单。

我想使用远程调用来查看是否存在电子邮件。

但是,我遇到了困难。

表单不断返回消息“请输入有效的电子邮件地址”

我一直在关注这个教程:http://sleekd.com/tutorials/jquery-validation-in-ruby-on-rails/

以下是我目前的代码:

JS 文件

 $(document).ready(function() {
$("#new_account").validate({
    rules: {
        "account[name]": {required:true},
        "account[email]": {required:true, email:true, remote:"/check_email"},
        "account[password]": {required:true},
        "account[gender]": {required:true}
    }
});
 });

路线

match 'check_email/:email' => 'accounts#checkEmail', :as => :check_email

控制器

 def checkEmail
account = Account.getAccountByEmail(params[:email])

respond_to do |format|
    format.json {render :json => !account}
end
end

感谢任何帮助。

谢谢,

布赖恩

【问题讨论】:

    标签: jquery ruby-on-rails jquery-plugins


    【解决方案1】:

    检查getAccountByEmail 的输出,当你给它一个已知的地址和通过rails console 给它一个新的电子邮件地址时。要使其始终返回 true,您的变量 account 必须是 falsenil。这就是我要开始的地方。

    【讨论】:

      【解决方案2】:

      不确定这是否对您有帮助(对此感到抱歉),但肯定值得一试。但是,请按照文森特解决方案中的说明首先进行。帐户的价值可能是问题所在。

      您是否检查过此 gem 以进行客户端验证。它位于https://github.com/bcardarella/client_side_validations 它易于使用,您甚至不需要编写自己的js。

      上面也有 railscast http://railscasts.com/episodes/263-client-side-validations

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-17
        • 2011-05-09
        • 2011-07-04
        • 2016-08-04
        • 1970-01-01
        相关资源
        最近更新 更多