ruby-on-rails – 添加自定义路由到Rails应用程序
发布时间:2020-12-16 21:15:11 所属栏目:百科 来源:网络整理
导读:我已经读过 the Rails Guides了. 我想要设置的是以下路由到路由到’profiles’控制器: GET个人资料/慈善机构 – 应显示所有慈善机构 GET个人资料/图表/:id应该显示一个特定的慈善机构 GET个人资料/捐赠者 – 应显示所有捐赠者 GET个人资料/捐赠者/:id –
我已经读过
the Rails Guides了.
我想要设置的是以下路由到路由到’profiles’控制器: GET个人资料/慈善机构 – 应显示所有慈善机构 我创建了配置文件控制器和两种方法:慈善机构和捐赠者. 这就是我需要的吗? 解决方法
以下将根据您的需要设置路由,但会将它们映射到:index和:show of CharitiesController和DonorsController:
namespace :profiles do # Actions: charities#index and charities#show resources :charities,:only => [:index,:show] # Actions: donors#index and donors#show resources :donors,: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' 以下是您所经历的指南中的相关部分: > Resource Routing: the Rails Default – Controller Namespaces and Routing (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |