我已经读过导轨指南 http://guides.rubyonrails.org/routing.html.
我想要设置的是路由到“配置文件”控制器的以下路由:
GET profiles/charities
- 应显示所有慈善机构
GET profiles/charties/:id
应显示特定的慈善机构
GET profiles/donors
- 应显示所有捐赠者
GET profiles/donors/:id
- 应显示特定的捐赠者
我创建了配置文件控制器和两种方法:慈善机构和捐助者。
这就是我所需要的一切吗?
下面将为您设置所需的路线,但会将它们映射到:index
and :show
of CharitiesController
and DonorsController
:
namespace :profiles do
# Actions: charities#index and charities#show
resources :charities, :only => [:index, :show]
# Actions: donors#index and donors#show
resources :donors, :only => [:index, :show]
end
当设置自定义路由更合适时,可以这样做:
get 'profiles/charities', :to => 'profiles#charities_index'
get 'profiles/charities/:id', :to => 'profiles#charities_show'
get 'profiles/donors', :to => 'profiles#donor_index'
get 'profiles/donors/:id', :to => 'profiles#donor_show'
以下是您正在阅读的指南中的相关部分:
- 资源路由:Rails 默认 - 控制器命名空间和路由 http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
- 非资源路由 - 命名路由 http://guides.rubyonrails.org/routing.html#naming-routes
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)