# Link\_to problem

**URL:** <https://www.ruby-forum.com/t/link-to-problem/126495>\
**Category:** Rails\
**Created:** [January 18, 2008, 7:02pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495 "2008-01-18T19:02:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 7:02pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/1 "2008-01-18T19:02:00Z")

</div>

hi @ all

I create a new archiv.html.erb and a archiv method in the controller.  
Now, I would like to link from index.html.erb to archiv.html.erb. I  
tried to use \<%= link\_to ‘archive’, archiv\_xxx\_path %\> but it doesn’t  
run.  
It appears a error message “SyntaxError in xxx#index”.

Does anyone know, how I can enhance this problem?

thanks a lot…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/2 "2008-01-18T19:34:02Z")

</div>

Hi,  
You can use \<%= link\_to ‘archive’, :action =\> ‘archive’ %\> in the view.

Then define an action in your controller. To do this, all you need is:  
def archive  
end  
This will automatically go to a page titled “archive” in your  
controller’s view, ex: archive.rhtml

Good luck,

- Jeff

K. R. wrote:

> hi @ all
> 
> I create a new archiv.html.erb and a archiv method in the controller.  
> Now, I would like to link from index.html.erb to archiv.html.erb. I  
> tried to use \<%= link\_to ‘archive’, archiv\_xxx\_path %\> but it doesn’t  
> run.  
> It appears a error message “SyntaxError in xxx#index”.
> 
> Does anyone know, how I can enhance this problem?
> 
> thanks a lot…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 7:43pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/3 "2008-01-18T19:43:13Z")

</div>

I’ve do this but it appears the error:  
"ActiveRecord::RecordNotFound in xxxController#show  
Couldn’t find xxx with ID=archiv "

It seems like a routing problem, isn’t it?

Jeff M. wrote:

> Hi,  
> You can use \<%= link\_to ‘archive’, :action =\> ‘archive’ %\> in the view.
> 
> Then define an action in your controller. To do this, all you need is:  
> def archive  
> end  
> This will automatically go to a page titled “archive” in your  
> controller’s view, ex: archive.rhtml
> 
> Good luck,
> 
> - Jeff

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/4 "2008-01-18T19:53:15Z")

</div>

That I’m not so sure on… Is your action defined in a different  
controller? If so, you can use:  
\<%= link\_to ‘action’, :controller =\> ‘ControllerName’, :action =\>  
‘ActionName’ %\>

Hope it helps… Other than that, I don’t know what that error is…

K. R. wrote:

> I’ve do this but it appears the error:  
> "ActiveRecord::RecordNotFound in xxxController#show  
> Couldn’t find xxx with ID=archiv "
> 
> It seems like a routing problem, isn’t it?
> 
> Jeff M. wrote:
> 
> > Hi,  
> > You can use \<%= link\_to ‘archive’, :action =\> ‘archive’ %\> in the view.
> > 
> > Then define an action in your controller. To do this, all you need is:  
> > def archive  
> > end  
> > This will automatically go to a page titled “archive” in your  
> > controller’s view, ex: archive.rhtml
> > 
> > Good luck,
> > 
> > - Jeff

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/5 "2008-01-18T21:15:57Z")

</div>

hmmm… I’m pretty new at RoR, so I’m not sure about this, but have you  
tried naming it something other than “archive”? Perhaps it is a built-in  
method or class or something that is throwing off your statement. Try  
“archive\_data” or something.

K. R. wrote:

> No, both methods are in the same controller - so I don’t need the  
> :controller statement.
> 
> In the new version of rails (2.0), I can use for example \<%= link\_to  
> ‘show’, show\_xxx\_path %\>. Why can’t I use the same principle with the  
> archive? I want to use \<%= link\_to ‘archive’, archiv\_xxx\_path %\> but it  
> doesn’t run!
> 
> Jeff M. wrote:
> 
> > That I’m not so sure on… Is your action defined in a different  
> > controller? If so, you can use:  
> > \<%= link\_to ‘action’, :controller =\> ‘ControllerName’, :action =\>  
> > ‘ActionName’ %\>
> > 
> > Hope it helps… Other than that, I don’t know what that error is…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/6 "2008-01-18T20:21:36Z")

</div>

No, both methods are in the same controller - so I don’t need the  
:controller statement.

In the new version of rails (2.0), I can use for example \<%= link\_to  
‘show’, show\_xxx\_path %\>. Why can’t I use the same principle with the  
archive? I want to use \<%= link\_to ‘archive’, archiv\_xxx\_path %\> but it  
doesn’t run!

Jeff M. wrote:

> That I’m not so sure on… Is your action defined in a different  
> controller? If so, you can use:  
> \<%= link\_to ‘action’, :controller =\> ‘ControllerName’, :action =\>  
> ‘ActionName’ %\>
> 
> Hope it helps… Other than that, I don’t know what that error is…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/7 "2008-01-18T22:06:35Z")

</div>

Hi K. R.,

The record not found error is due to the RESTful interpretation of  
URLs by Rails. Given the URL …

[http://localhost:3000/xxx/archive](http://localhost:3000/xxx/archive)

… Rails rails assumes that you are calling the ‘show’ action on the  
‘xxx’ controller with ‘archiv’ as the ID of the model instance to be  
shown.

To get rails to understand that ‘archiv’ is a new action, you need to  
edit the routes.rb file and add appropriate routes using either  
the :collection option (if the archiv action works with a collection  
of model instances) or with the :member option (if you are working  
with only one instance of the model).

Check out the screencasts below for a quick intro to routes and custom  
actions

Named routes

> **[\#34 Named Routes - RailsCasts](http://railscasts.com/episodes/34-named-routes)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Custom REST actions

> **[\#35 Custom REST Actions - RailsCasts](http://railscasts.com/episodes/35-custom-rest-actions)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Cheers,  
Akbar

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/8 "2008-01-18T21:29:26Z")

</div>

sorry, but it isn’t a problem with the naming convention. When I put an  
id behind the url, then the application runs. For example:  
[http://localhost:3000/xxx/archive/1](http://localhost:3000/xxx/archive/1) but with  
[http://localhost:3000/xxx/archive](http://localhost:3000/xxx/archive) it appears a error message. So I must  
change the routes.rb but I don’t know how…  
Now when I use [http://localhost:3000/xxx/archive](http://localhost:3000/xxx/archive) the interpreter means,  
that archive is an id and not a method.

Jeff M. wrote:

> hmmm… I’m pretty new at RoR, so I’m not sure about this, but have you  
> tried naming it something other than “archive”? Perhaps it is a built-in  
> method or class or something that is throwing off your statement. Try  
> “archive\_data” or something.

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [January 18, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/link-to-problem/126495/9 "2008-01-18T22:57:57Z")

</div>

You need to specify that your resource have a new method, i.e :

map.resources user do |users|  
user.resources :tournament, :member=\>{:stats=\>:get }  
end

And now you can request the url  
“/users/:user\_id/tournaments/:tournament\_id/stats” with  
stats\_user\_tournament(@user, @tournament)

2008/1/18, K. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ## thanks a lot…
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

## –

Pedro Del G.

Email : removed\_email\_address@domain.invalid
