在我的rails应用程序中,我使用资源丰富的路由进行基本的CRUD功能。但在某些情况下,我正在向控制器添加新的视图和方法(例如,特定的报告功能)。这些是否会自动包含在资源充足的路线中?或者我必须在routes.rb中获取或匹配每一行吗?
以下是我现在如何使用routes.rb ...似乎如果我必须明确指定所有内容,那么随着应用程序的增长,这将变得非常好...
resources :procedures
resources :headlines
devise_for :users
resources :services
resources :headlines
get "welcome/index"
get "welcome/profile"
get "welcome/kpi"
get "welcome/inventory"
get "public/index"
match "insurancelist" => "appointments#insurancelist"
get "admin/index"
get "dentrix/index"
get "dexis/index"
get "eaglesoft/index"
get "reports/index"
get "reports/dentist"
get "reports/office"
get "reports/collections"
resources :patients
shallow do
resources :locations do
resources :practitioners do
resources :timecards
resources :appointments
end
end
end
答案 0 :(得分:1)
您应该阅读官方Rails指南here
中的路线这里有一些关于你问题的快速提示(因为我看到你想在你的资源中添加一些非REST动作)。
我们来看看。例如,您有一个项目模型和projects
资源。并且您希望为项目项添加print
操作(例如,在该操作中,您将准备报告打印在纸上),并为整个项目资源添加published
操作(作为选择操作仅限某种报道):
您应该写下routes.rb
下一行:
resources :projects do
collection do
get :published
end
member do
get :print
end
end
该代码为您提供了下一条路线:
GET /projects => projects#index
GET /projects/published => projects#published
GET /projects/new => projects#new
POST /projects => projects#create
DELETE /projects/:id => projects#destroy
PUT /projects/:id => projects#update
GET /projects/:id => projects#show
GET /projects/:id/edit => projects#edit
GET /projects/:id/print => projects#print
答案 1 :(得分:1)
这些额外的路线不会包含在资源充足的路线中。对于您的示例中的路由,遗憾的是,实际上没有办法压缩它们,并且它们每个都需要路由文件中的单独行。