0

初歩的なAPIを試していますが、やや岐路に立っており、どのように進めればよいかわかりません。一般的な要点は、/authenticate.jsonにユーザー名とパスワードが提供され、その代わりにアクセストークンを受け取ることです。

GETリクエストを行うと、必要な情報を取得します。POSTを介して実行しようとすると、エラーがスローされます。

No route matches {:action=>"show", :controller=>"users", :id=>#<User access_token: "8922a3718bbe2a441a5ddddece3053a647941863b5ff2cad007...">}

ルート.rb

match '/authenticate' => 'user_functions#authenticate', :via => [:post, :get]

コントローラー内の認証定義は次のようになります(私はそれが不器用であることを知っています、私はRoR / Rubyに完全に精通していません)

def authenticate
if params['email'] and params['password']
  userSearch = User.find(:all, :conditions => ['email = ?', params[:email]], :limit => 1)
  if userSearch.count == 1 
    hash = Digest::SHA2.new << "#{userSearch.first.password_salt}#{params['password']}"
    if hash.hexdigest == userSearch.first.password_hash
      access_array = {"access_token" => userSearch.first.access_token}
      userAccessDetails = User.find(userSearch.first.id, :select => "access_token")
      respond_with userAccessDetails
    else
      respond_with 'Invalid credentials'
    end
  else
    respond_with 'Failed'
  end
else
  respond_with 'No credentials provided'
end

終わり

誰かが私を助けたり、正しい方向に向けたりすることができれば、私はそれをいただければ幸いです。ありがとう。

4

1 に答える 1

0

問題は、渡すユーザーオブジェクトにIDがないことです。クエリでは、アクセストークンのみを選択します。

IDも選択してみてください:

userAccessDetails = User.find(userSearch.first.id、:select => "access_token、id")

于 2013-03-10T21:45:06.113 に答える