Jeffrey Basurto Jeffrey Basurto - 9 months ago 24
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?


You can do it like this:

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

and differentiate based on something param