3

我正在使用cardmagic/contacts gem从我的应用程序中的电子邮件地址导入联系人。它工作正常,但我的问题是我想赶上认证错误像错误的用户名/密码为下面的代码。从cardmagic /联系人中检索联系人时的Rescue Authentication Error gem

@contacts = Contacts.guess(@username, @password) 

我想向用户显示该错误。

我试过这个,但不适合我。

@contacts = Contacts.guess(@username, @password) rescue Contacts::AuthenticationError 

所以请指导我如何去做。 谢谢。

回答

0
def import 
    @username = params[:user] 
    @password = params[:pass] 
    begin 
    @contacts = Contacts.guess(@username, @password) 
    rescue 
    @error_message = e.message 
    render :action => 'new' 
    end 
    redirect_to root_path 
end 

new.html.erb:

<% if @error_message %> 
    <%= @error_message %> 
<% end %> 
HTML to get username & password inputs 
+0

嘿阿伦感谢稳定部队的快速回复,但仍即使我在EAMIL和密码输入任何随机值field.My应用是它不捕捉错误只是显示captcha或雅虎的例外情况已经改变了它的协议等。你有什么想法来解决这个问题吗? –

+0

你可以请你发布我们的例外吗? –

+0

的GData ::客户:: CaptchaError在InvitationsController#import_contacts CaptchaRequired:验证码ctoken = zYyBi97vDOUWnh3I-kIOkLt34aqHj6Q_EpVlzCw4fbqxlswgL08KNxoyHe1hubDqMzi7RCXaG_YpNpmIRcgOn11CHNTRL6uRC5T79Y%3AM2hcehJllGlPV27H6QzSFw –

相关问题