我有一个控制器,clients_controller
具有相应的索引,显示,编辑,删除,新的和表单视图.有没有办法创建一个新的视图,就像clients/prospects.html.erb
行为一样clients/index.html.erb
,除了路由clients/prospects/
?
我试过这个:
match '/clients/prospects' => 'clients#prospects'
还有一些其他的东西routes.rb
,但当然得到错误"找不到具有id =潜在客户的客户".
这里的目标基本上是拥有潜在客户视图和客户视图,并且通过简单地将隐藏字段切换为1,它(在用户的脑海中)将潜在客户转变为客户端(它是类似CRM的应用程序).
你需要做几件事.首先,您需要在任何通用路线之前放置自定义路线.否则Rails假定"前景"这个词是show动作的id.例:
get '/clients/prospects' => 'clients#prospects' # or match for older Rails versions resources :clients
您还需要在ClientsController中复制/粘贴索引方法并将其命名为prospect.例:
class ClientsController < ApplicationController def index @clients = Client.where(prospect: false) end def prospects @prospects = Client.where(prospect: true) end end
最后,您需要复制index.html.erb视图并将副本命名为prospects.html.erb.在上面的示例中,您将不得不使用@prospects实例变量.