Rails に基づいて REST API を開発しています。me
この API を使用するには、ログインする必要があります。それに関して、ログインしたユーザー情報の json を返すメソッドをユーザー コントローラーに作成したいと思います。:id
したがって、 URL で渡す必要はありません。http://domain.com/api/users/meに電話したいだけです
だから私はこれを試しました:
namespace :api, defaults: { format: 'json' } do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :tokens, :only => [:create, :destroy]
resources :users, :only => [:index, :update] do
# I tried this
match 'me', :via => :get
# => api_user_me GET /api/users/:user_id/me(.:format) api/v1/users#me {:format=>"json"}
# Then I tried this
member do
get 'me'
end
# => me_api_user GET /api/users/:id/me(.:format) api/v1/users#me {:format=>"json"}
end
end
end
ご覧のとおり、私のルートは ID を待機していますが、devise のようなものを取得したいと考えています。current_user
IDに基づくもの。以下の例:
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
この例では、id をパラメーターとして渡さずに現在のユーザー パスワードを編集できます。
メンバーの代わりにコレクションを使用することもできますが、それはダーティ バイパスです...
誰にもアイデアがありますか?ありがとうございました