Absolutely there is. You can use a parameter directly in your route. Even further, you can then use that parameter directly in your query, rather than using a case statement.
#routes.rb
get 'suggestions/:type', to: 'suggestions#index'
# suggestions_controller.rb
def index
@suggestions = Suggestion.where(suggestion_type: params[:type])
end
It’s always a better practice to base your controller actions after parameters, rather than doing any interpretation of the path or request objects.
Hope it works!
2
solved ElegantRails – Multiple Routes to one Controller Action