views:

177

answers:

1

So I'm trying to use link_to to create a link in my Rails app and trying to add a CSS class to certain links. The problem that I have is that when I add my html options to the link_to arguments, the links don't get created and I end up with nothing. Here's my code:

<%=link_to( image_tag(@beetle.icon_img, :width=>30, :alt=>"Beetle", :border=>0) , beetle, :html=>{:class=>"work"}) %>

I also tried variations of this and it still didn't work. For example,

<%=link_to( image_tag(@beetle.icon_img, :width=>30, :alt=>"Beetle", :border=>0) , beetle, :class=>"work") %>

The method also exhibits some strange behavior, which I think might be the culprit. If I go straight to the page, no POST or GET requests, link_to works properly and the links and images render correctly, which is to say that they actually DO render. However, the way that I would like to get to the page is by form POST request in a previous page whose action is the results page I'm trying to get to.

Thanks for any help you can provide!

EDIT: I'm not sure exactly what the problem was, but I solved it by changing the form's method to GET instead of POST.

A: 

It's most likely because the POST request is hitting a different method (new), rather than (show). You must supply the proper instance variables to the view. You seem to be referencing both @beetle and beetle. Have a look at all of those variables, since that appears to be the POST problem.

Sean McCann
That's my mistake unfortunately. I forgot to remove the @ from my previous code but they reference the same thing.
CCSab
So I've got two link_to helpers working on the same page with the same beetle variable. Both links are created and display properly if there aren't any html options appended, regardless of whether or not it's a POST request. The problem only occurs when I append the html options at the end.
CCSab