Ruby on rails 3 如何创建自定义rails命名空间路由
我第一次开始使用带有名称空间的路由。我理解以下内容的概念Ruby on rails 3 如何创建自定义rails命名空间路由,ruby-on-rails-3,namespaces,routes,Ruby On Rails 3,Namespaces,Routes,我第一次开始使用带有名称空间的路由。我理解以下内容的概念 namespace :company do namespace :project, defaults:{format: 'json'} do resources :registration end end 我的控制器看起来是这样的 class Company::Project::RegistrationController < ApplicationController before
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
在名称空间块中是否有这样做的方法
----------变动后--------------
在第一个答案中做了下面的建议更改后,这就是running>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"}
我希望我对你的理解是正确的。是否要为子管线添加其他管线 方法可以是这样的:
namespace :company do
namespace :project, defaults:{format: 'json'} do
resource :registration do
member do
get 'register', :to => 'registration#register', :as => :register
get 'entry', :to => 'registration#enrty', :as => :entry
end
end
end
end
我希望我对你的理解是正确的。是否要为子管线添加其他管线 方法可以是这样的:
namespace :company do
namespace :project, defaults:{format: 'json'} do
resource :registration do
member do
get 'register', :to => 'registration#register', :as => :register
get 'entry', :to => 'registration#enrty', :as => :entry
end
end
end
end
如果我运行rake routes,我会看到公司/项目/注册#注册为一个路由,但在浏览器中,如果我点击url,我会得到一个路由错误,该错误不存在,请转到公司/项目/注册/注册。请在此处复制您的
rake routes
输出。将路由添加到上面的答案中。它们在评论区的位置太长。对不起,我看不到您的rake routes
输出。请编辑您的问题描述,并添加您有company
基于名称空间的路由(所有基于名称空间的路由)的部分。确定运行rake路由的路由应添加到“问题/问题区域”如果我运行rake routes,我会看到公司/项目/注册#注册为一个路由,但在浏览器中,如果我点击url,我会得到一个路由错误,该错误不存在,请转到公司/项目/注册/注册。请在此处复制您的rake routes
输出。将路由添加到上面的答案中。它们在评论区的位置太长。对不起,我看不到您的rake routes
输出。请编辑您的问题描述,并添加您有company
基于名称空间的路由(所有基于名称空间的路由)的部分。确定运行rake路由的路由应添加到“问题/问题区域”