【发布时间】:2012-05-24 13:23:42
【问题描述】:
我第一次开始使用带有命名空间的路由。我理解以下内容的概念。
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"
有没有办法在命名空间块中做到这一点?
----------修改后-------------- 在下面的第一个答案中做出建议的更改后,这就是运行 >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"}
【问题讨论】:
标签: ruby-on-rails-3 namespaces routes