【发布时间】:2014-11-03 20:57:24
【问题描述】:
我正在使用 Rails-Api (4),我只需要三个路由用于我的命名空间路由文件。
在我的 routes.rb 文件中,我正在尝试这样做:
namespace :api do
namespace :v1 do
resources :documents, only: [:get, :create]
resource :system_status, only: [:get]
end
end
rake routes 只给我这个:
Prefix Verb URI Pattern Controller#Action
api_v1_documents POST /api/v1/documents(.:format) api/v1/documents#create
如果关闭only:,它会起作用并为我提供所有路线(我不想要)。
我也试过这个:
namespace :api do
namespace :v1 do
post '/documents', to: 'documents#create'
get '/documents/:id', to: 'documents#show'
get '/system_status', to: 'system_status#show'
end
end
在rake routes 中得到这个奇怪的输出:
Prefix Verb URI Pattern Controller#Action
api_v1_documents POST /api/v1/documents(.:format) api/v1/documents#create
api_v1 GET /api/v1/documents/:id(.:format) api/v1/documents#show
api_v1_system_status GET /api/v1/system_status(.:format) api/v1/system_status#show
不确定documents#show 的前缀是api_v1 是怎么回事。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rails-routing rails-api