开发者

Rails Link_To doesn't add a CSS Class correctly

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 开发者_如何学Gowhat the problem was, but I solved it by changing the form's method to GET instead of POST.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜