[英]Defining a custom route in a namespaced api in rails application
我已經在Rails 5項目中創建了一個命名空間的api。 我的config / routes.rb中有以下內容
Rails.application.routes.draw do
post 'api_user_token' => 'api_user_token#create'
namespace :api do
namespace :v1 do
resources :events
end
end
end
事件控制器
module Api::V1
class EventsController < ApiController
#Code here
end
end
API控制器
module Api::V1
class ApiController < ApplicationController
before_action :authenticate_api_user
respond_to :json
def register
end
end
end
我希望“ / api / v1 / register”路由轉到我的api控制器中定義的register方法 。 在這種情況下,如何定義路線?
謝謝
namespace :api do
namespace :v1 do
resources :events
post :register, to: 'apis#register'
end
end
這將產生
api_v1_register POST /api/v1/register(.:format) api/v1/apis#register
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.