Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 759
Misha M Avatar asked Oct 18 '25 19:10

Misha M


1 Answers

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) %>
like image 147
waldyr.ar Avatar answered Oct 21 '25 08:10

waldyr.ar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!