Jeffrey Basurto Jeffrey Basurto - 2 years ago 61
Ruby Question

Can Ruby on Rails have multiple routes to one action while being able to differentiate in action?

What I'd like to do is something like this

get 'example/:id' => 'example#same_action'

and also

get 'slightly_different/:id' => 'example#same_action'

but then be able to differentiate inside of
as to which rule was used.

Is this better achieved by refactoring into model and partials?

Answer Source

You can do it like this:

get ':something/:id', constraints: { something: /example|slightly_different/ }

and differentiate based on something param

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download