What is the most elegant way to have multiple routes go to the same controller action?
I have:
get 'dashboard', to: 'dashboard#index'
get 'dashboard/pending', to: 'dashboard#index'
get 'dashboard/live', to: 'dashboard#index'
get 'dashboard/sold', to: 'dashboard#index'
This is quite ugly. Any "more elegant" recommendations?
Bonus points for a one liner.
Why not have just one route and one controller action, and differ the functionality based on params passed to it?
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) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With