3

cardmagic / contacts gemを使用して、アプリケーションの電子メールアドレスから連絡先をインポートしています。それは正常に動作していますが、私の問題は、次のコードの間違ったユーザー名/パスワードなどの認証エラーをキャッチしたいことです。

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

そのエラーをユーザーに表示したいと思います。

私はこれを試しましたが、うまくいきませんでした。

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

だから私にそうする方法を教えてください。ありがとうございました。

4

1 に答える 1

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
于 2011-08-17T05:50:41.147 に答える