ruby - Elegant Rails: multiple routes, same controller action -


what elegant way have multiple routes go same controller action?

i have:

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

this quite ugly. "more elegant" recommendations?
bonus points 1 liner.

why not have 1 route , 1 controller action, , differ functionality based on params passed it?

config/routes.rb:

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

app/controller/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 

links in views

  • pending: <%= link_to "pending", dashboard_path(pending: true) %>
  • live: <%= link_to "live", dashboard_path(live: true) %>
  • sold: <%= link_to "sold", dashboard_path(sold: true) %>

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -