Misha M
Misha M

Reputation: 11299

How to make link_to and custom URL work together on Rails

I have a custom vanity URL setup, ala GitHub:

http://foo.com/:user/:stuff

I have routes to handle this as well:

match '/:user/:stuff', to: 'stuffs#show'

How can I make link_to work with this route for stuff?

link_to @stuff.name, @stuff

Upvotes: 4

Views: 2618

Answers (1)

waldyr.ar
waldyr.ar

Reputation: 15224

You can make it through a route alias:

match '/:user/:stuff' => 'stuffs#show', :as => 'users_stuff'

And in your view call it normally, passing the two parameters:

<%= link_to 'Show', users_stuff_path(current_user,3) %>

Upvotes: 6

Related Questions