我读过关于the Rails Guides的文章。
GET profiles/charities -应该显示所有的慈善机构
GET profiles/charties/:id应该展示一个特定的慈善机构
GET profiles/donors -应该显示所有的捐赠者
GET profiles/donors/:id -应显示特定的捐赠者
我已经创建了配置文件控制器和两个方法:慈善机构和捐赠者。
这就是我需要的全部吗?
发布于 2013-10-16 10:39:57
下面将为您想要的内容设置路由,但会将它们映射到CharitiesController和DonorsController的:index和:show
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'以下是您正在阅读的指南中的相关部分:
发布于 2013-10-16 11:05:31
慈善机构和捐赠者似乎是嵌套的资源。如果是这样,那么在config/routes.rb文件中应该有如下内容,
resources :profiles do
resources :charities
resources :donors
end因为这些是嵌套的资源,所以在配置文件控制器中不需要名为慈善和捐赠者的两个方法。事实上,根据你的应用程序,你可能需要为你的慈善机构和捐赠者单独的控制器和/或模型。
https://stackoverflow.com/questions/19394192
复制相似问题