Rails routes: GET without param :id

后端 未结 7 1017
名媛妹妹
名媛妹妹 2021-01-01 08:56

I\'m developing a REST api based on rails. To use this api, you MUST be logged in. Regarding that, I\'d like to create a method me in my user controller that wi

7条回答
  •  一整个雨季
    2021-01-01 09:17

    When you create a route nested within a resource, you can mention, whether it is member action or a collection action.

    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, :collection => true
    ...
    ...
    

提交回复
热议问题