优雅的Rails:多个路由,相同的控制器操作

让多个路由进入同一控制器操作的最优雅方法是什么?

我有:

get 'dashboard', to: 'dashboard#index' get 'dashboard/pending', to: 'dashboard#index' get 'dashboard/live', to: 'dashboard#index' get 'dashboard/sold', to: 'dashboard#index' 

这很难看。 任何“更优雅”的建议?
一个class轮的奖励积分。

为什么不只有一个路由和一个控制器动作,并根据传递给它的参数不同的function?

配置/ routes.rb文件:

 get 'dashboard', to: 'dashboard#index' 

应用程序/控制器/ dashboard_controller.rb

 def index ... if params[:pending] # pending related stuff end if params[:live] # live related stuff end if params[:sold] # sold related stuff end ... end 

视图中的链接

  • pending: <%= link_to "Pending", dashboard_path(pending: true) %>
  • live: <%= link_to "Live", dashboard_path(live: true) %>
  • 已售出: <%= link_to "Sold", dashboard_path(sold: true) %>