我有一个页面控制器和视图。在views / pages文件夹中,我有以下视图:
home.html.erb
activities.html.erb
如果我在config / routes.rb中添加以下内容:
resources :pages do
resources :home
resources: activities
end
我是否可以按如下方式引用主页和活动页面的路径:
pages_home_path
pages_activities_path
答案 0 :(得分:1)
路线定义中有拼写错误,应该是:
resources :pages do
resources :home
resources :activities
end
您可以通过运行bundle exec rake routes
来验证命名路由的位置。这是此定义的输出:
Prefix Verb URI Pattern Controller#Action
page_home_index GET /pages/:page_id/home(.:format) home#index
POST /pages/:page_id/home(.:format) home#create
new_page_home GET /pages/:page_id/home/new(.:format) home#new
edit_page_home GET /pages/:page_id/home/:id/edit(.:format) home#edit
page_home GET /pages/:page_id/home/:id(.:format) home#show
PATCH /pages/:page_id/home/:id(.:format) home#update
PUT /pages/:page_id/home/:id(.:format) home#update
DELETE /pages/:page_id/home/:id(.:format) home#destroy
page_activities GET /pages/:page_id/activities(.:format) activities#index
POST /pages/:page_id/activities(.:format) activities#create
new_page_activity GET /pages/:page_id/activities/new(.:format) activities#new
edit_page_activity GET /pages/:page_id/activities/:id/edit(.:format) activities#edit
page_activity GET /pages/:page_id/activities/:id(.:format) activities#show
PATCH /pages/:page_id/activities/:id(.:format) activities#update
PUT /pages/:page_id/activities/:id(.:format) activities#update
DELETE /pages/:page_id/activities/:id(.:format) activities#destroy
pages GET /pages(.:format) pages#index
POST /pages(.:format) pages#create
new_page GET /pages/new(.:format) pages#new
edit_page GET /pages/:id/edit(.:format) pages#edit
page GET /pages/:id(.:format) pages#show
PATCH /pages/:id(.:format) pages#update
PUT /pages/:id(.:format) pages#update
DELETE /pages/:id(.:format) pages#destroy
然后,您可以将这些前缀用作page_activity_path
或page_activity_url
。