# Link\_to ---- articles detail - basic help

**URL:** <https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062>\
**Category:** Rails\
**Created:** [February 13, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062 "2008-02-13T22:17:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![liam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@liam](https://www.ruby-forum.com/u/liam)\
**Post date:** [February 13, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062/1 "2008-02-13T22:17:55Z")

</div>

I have a basic blog with images - and in the index.rhtml view file I  
have the following:

\<% @contents.each do |content| -%\> - \<%= content.title %\>
- \<%= content.summary %\>
- \<%= link\_to image\_tag(content.image.public\_filename(:thumb)), content, :action =\> 'show', :id =\> content %\> 
- \<%= link\_to content, :action =\> 'show', :id =\> content %\>
\<% end -%\>

As soon as I add a name for the link - e.g.

\<%= link\_to ‘view content detail’, content, :action =\> ‘show’, :id =\>  
content %\>

the link no longer goes to the correct detail page - instead just goes  
back to “index”. (the same applies to the link\_to from the image)

Without the ‘view article detail’ inserted - the ‘#’ links correctly  
url = contents/1 … contents/2 …etc etc

just in case…  
(routes.rb = map.resources :contents)

What am I missing here?

Thanks in advance

(and yes (previous post), I am still struggling with the IE7 CSS  
problem!!)

---

<div class="post-metadata">

**Author:** ![liam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@liam](https://www.ruby-forum.com/u/liam)\
**Post date:** [February 14, 2008, 6:41am UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062/2 "2008-02-14T06:41:42Z")

</div>

On Feb 13, 1:17 pm, Liam 11 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a basic blog with images - and in the index.rhtml view file I  
> have the following:  
> […]

I’m certainly no expert, but so far I’ve found that editing view/foo/  
show.rhtml achieves the purposes I need. I’m curious about why you’re  
editing index.rhtml – what does that accomplish?

-Thufir

---

<div class="post-metadata">

**Author:** ![liam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@liam](https://www.ruby-forum.com/u/liam)\
**Post date:** [February 14, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062/3 "2008-02-14T14:08:37Z")

</div>

On Feb 13, 9:17 pm, Liam 11 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> As soon as I add a name for the link - e.g.
> 
> \<%= link\_to ‘view content detail’, content, :action =\> ‘show’, :id =\>  
> content %\>

Does removing the first content variable from your link help?

The link\_to helper normally takes the form of \<%= link\_to “Link Text  
Here”, url\_here %\> Also, as you’re using RESTful routes, you can  
rewrite your link as:

\<%= link\_to “View link details”, content\_url(content) %\>

Robin

---

<div class="post-metadata">

**Author:** ![liam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@liam](https://www.ruby-forum.com/u/liam)\
**Post date:** [February 14, 2008, 9:07pm UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062/4 "2008-02-14T21:07:20Z")

</div>

AndyV wrote:

> I’d strongly recommend using the link\_to format that Robin  
> recommended. As for your specific problem, check the development  
> log. What kind of http req are you getting, GET or POST? My  
> suspicion is that you’re getting a post which Rails interprets as an  
> insert into the collection (probably creating a lot of empty records  
> at this point!) and then you’re being redirected back to the index  
> after the insert.
> 
> With Robin’s method you can be sure of the http request by:
> 
> \<%= link\_to “View link details”, content\_url(content, :method=\>:get)  
> %\>

Fantastic - thanks to all - everything works perfectly now

---

<div class="post-metadata">

**Author:** ![liam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b9e5f3/32.png) [@liam](https://www.ruby-forum.com/u/liam)\
**Post date:** [February 14, 2008, 9:03pm UTC](https://www.ruby-forum.com/t/link-to-articles-detail-basic-help/129062/5 "2008-02-14T21:03:17Z")

</div>

I’d strongly recommend using the link\_to format that Robin  
recommended. As for your specific problem, check the development  
log. What kind of http req are you getting, GET or POST? My  
suspicion is that you’re getting a post which Rails interprets as an  
insert into the collection (probably creating a lot of empty records  
at this point!) and then you’re being redirected back to the index  
after the insert.

With Robin’s method you can be sure of the http request by:

\<%= link\_to “View link details”, content\_url(content, :method=\>:get)  
%\>
