我第一次开始使用带有命名空间的路由。我理解以下内容的概念。
namespace :company do
namespace :project, defaults:{format: 'json'} do
resources :registration
end
end
我的控制器看起来像这样
class Company::Project::RegistrationController < ApplicationController
before_filter :authenticate_user!
#responds_to :json
def register
end
def entry
end
end
因此,在资源中,我想为register
and定义路线,entry
但我没有找到任何真正告诉我如何做到这一点的东西。我知道如果我不使用命名空间,那么我通常会在我的路由文件中执行类似的操作。
match 'company/project/registration/register' => "Registration#register"
有没有办法在命名空间块中做到这一点?
---------- 更改后 -------------- 在第一个答案中进行以下建议更改后,这就是运行 >rake routes 给我的
register_company_project_registration POST /company/project/registration/:id/register(.:format) company/project/Registration#register {:format=>"json"}
entry_company_project_registration POST /company/project/registration/:id/entry(.:format) company/project/Registration#enrty {:format=>"json"}
company_project_registration_index GET /company/project/registration(.:format) company/project/registration#index {:format=>"json"}
POST /company/project/registration(.:format) company/project/registration#create {:format=>"json"}
new_company_project_registration GET /company/project/registration/new(.:format) company/project/registration#new {:format=>"json"}
edit_company_project_registration GET /company/project/registration/:id/edit(.:format) company/project/registration#edit {:format=>"json"}
company_project_registration GET /company/project/registration/:id(.:format) company/project/registration#show {:format=>"json"}
PUT /company/project/registration/:id(.:format) company/project/registration#update {:format=>"json"}
DELETE /company/project/registration/:id(.:format) company/project/registration#destroy {:format=>"json"}