让多条路线相同的最优雅方式是什么 控制器动作?
我有:
get 'dashboard', to: 'dashboard#index'
get 'dashboard/pending', to: 'dashboard#index'
get 'dashboard/live', to: 'dashboard#index'
get 'dashboard/sold', to: 'dashboard#index'
这很难看。任何"更优雅"建议?
一个班轮的奖励积分。
答案 0 :(得分:10)
为什么不只有一个路由和一个控制器动作,并根据传递给它的参数不同的功能?
get 'dashboard', to: 'dashboard#index'
def index
...
if params[:pending]
# pending related stuff
end
if params[:live]
# live related stuff
end
if params[:sold]
# sold related stuff
end
...
end
<%= link_to "Pending", dashboard_path(pending: true) %>
<%= link_to "Live", dashboard_path(live: true) %>
<%= link_to "Sold", dashboard_path(sold: true) %>