1

I have a route for querying "Service" model:

resources :services, :path => 'services'

When GET requests for path /services/sn-uber i take param sn(service name) and find it in database. How to add there another param like sd(service-district)?

For example /services/sn-uber/sd-brooklyn or /services/sd-brooklyn so any param could be omitted.

pvf
  • 82
  • 1
  • 6

1 Answers1

2

Add something like this to your routes:

get 'services(/sn/:sn_name)(/sd/:sd_name)', controller: 'services', action: 'show'

Your url will look like:

  • /services/sn/uber/sd/brooklyn
    • params will be sn_name and sd_name
  • /services/sn/uber
    • param will be sn_name
  • /services/sd/brooklyn
    • param will be sd_name

If you want to keep your url like that /services/sn-uber/sd-brooklyn:

get 'services(/:sn_name)(/:sd_name)', controller: 'services', action: 'show'
Rémi Delhaye
  • 794
  • 3
  • 16