2011-11-17 90 views
1

我正在使用JQuery驗證插件來驗證我網站上的註冊表單。Ruby on Rails 3.0 JQuery驗證遠程

我想使用遠程調用來查看是否存在電子郵件。

但是,我有困難。

的形式保留返回消息「請輸入一個有效的電子郵件地址」

我一直在關注這個教程: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 

得到任何幫助。

謝謝

布賴恩

回答

1

檢查的getAccountByEmail的輸出,當你給它一個已知地址,當你給它通過rails console一個新的電子郵件地址。爲了始終返回true,您的變量account必須是falsenil。那就是我要開始的地方。