# Changing link\_to link location slightly

**URL:** <https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357>\
**Category:** Rails\
**Created:** [May 10, 2010, 7:44pm UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357 "2010-05-10T19:44:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 10, 2010, 7:44pm UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/1 "2010-05-10T19:44:43Z")

</div>

Hi,

Basically I’m just wondering how I can change my link\_to’s location  
slightly.

At the moment I have a system with categories and tutorials, and the  
categories have\_many tutorials.  
The link itself is like this:

\<%= link\_to ‘Next lesson’, @NextLesson, :controller =\>  
‘categories’, :id =\> (@category.id), :action =\> (@NextLesson) %\>

I’ve set the controller etc because my routes.rb file handles the  
routes like this:

map.connect ‘categories/:id/tutorials/:action’, :controller =\>  
‘categories’

So from this I figures the link would lead to: /categories/ID/  
tutorials/ID  
however it doesn’t, it just leads to: /tutorials/ID

Does anyone know how I can change it from /tutorials/TUTID to /  
categories/CATID/tutorials/TUTID ?

Thanks In Advance,

Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 10, 2010, 8:58pm UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/2 "2010-05-10T20:58:27Z")

</div>

Assuming you’re using REST (far better, IMO), although your map.connect  
would make me think otherwise…

map.resources :tutorials,  
:controller =\> “categories”  
:path\_prefix =\> “/category/:category\_id”,  
:name\_prefix =\> “category\_”

should yield /categories/category.id/tutorials/tutorial.id  
and category\_tutorial as a named route, with a link something like this:

\<%= link\_to ‘Next lesson’,  
category\_tutorial\_path(:category\_id =\> @category.id,  
:id =\> @NextLesson) %\>

I think, although your @NextLesson seems bizarre.

If that doesn’t work, have you done a “rake routes \>routes.lst”  
then looked at your routes.lst to see what routing you actually have?  
Rails will match the first route it finds given the inputs in the  
specified order.

[http://api.rubyonrails.org/classes/ActionController/Resources.html](http://api.rubyonrails.org/classes/ActionController/Resources.html)

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 11, 2010, 8:19am UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/3 "2010-05-11T08:19:55Z")

</div>

Adding your section into routes.rb seems to give me this error on  
attempting to run the server:

unexpected tASSOC, expecting kEND

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 11, 2010, 5:54pm UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/4 "2010-05-11T17:54:31Z")

</div>

map.resources :tutorials,  
:controller =\> “categories”  
:path\_prefix =\> “/category/:category\_id”,

There should be a comma at the end of the second line after  
“categories”, my bad.

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 11, 2010, 6:21pm UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/5 "2010-05-11T18:21:10Z")

</div>

THANK YOU SO MUCH!

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [May 11, 2010, 8:24am UTC](https://www.ruby-forum.com/t/changing-link-to-link-location-slightly/188357/6 "2010-05-11T08:24:00Z")

</div>

(dont know why the last post posted, I wasn’t done yet)

Please note the last error was for the path:prefix line.

Also on your route list thing it gives me this error (about the colon  
next to the path\_prefix line):

unexpected ‘,’ expecting kEND

(The server running also mentions then ‘,’ but not in as much details.

This means it wont let me rake the routes or whatever to see the  
routes.

Please Help,

Thanks In Advance,

Joe
