1
我开始首次使用带有命名空间的路由。我理解以下内容的概念。如何创建自定义导轨命名空间路由
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
和entry
的路线,我还没有发现任何东西,真的告诉我该怎么做。我知道如果我不使用命名空间,那么我通常会在我的路由文件中做这样的事情。
match 'company/project/registration/register' => "Registration#register"
有没有办法在命名空间块内做到这一点?
----------改变后-------------- 在第一个答案中提出下面的建议更改后,这就是运行>耙路线给我
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"}
是的...这就是我想要的!谢谢。 – mattwallace
如果我运行耙路线我看到公司/项目/注册#注册为路线,但在浏览器中,如果我打网址我得到一个路由错误,它不存在通过去公司/项目/注册/注册 – mattwallace
Plese在这里复制你的'rake routes'输出。 – thesis