0

Could anyone advise how to set out the following link_to please, i thought that any html option ( and that includes a class doesnt it?) should be in {}...

So i have this link_to at the moment

<%= link_to(@portfolio.previous_post) if @portfolio.previous_post %>

I would like to add a class of 'prev' as this has a background image within the css, rather than using text..I am unsure on where to put

:class => 'prev' or class: 'prev'

depending on preference of course

This doesn't work

<%= link_to(@portfolio.previous_post, { class: 'prev'}) if @portfolio.previous_post %>

Any help appreciated

Richlewis
  • 15,070
  • 37
  • 122
  • 283

1 Answers1

1

Something like this should work:

`    <% if @portfolio.previous_post %>
         <%= link_to "link_name",@portfolio.previous_post, class: "prev"%>
     <% end %>`

This should work as well:

`    <%= link_to_if(@portfolio.previous_post, "link_name", @portfolio.previous_post, 
        class: "prev") %>`

Once you provide a name for the url in addition to the url, everything seems to work.

rboling
  • 717
  • 1
  • 4
  • 8
  • neither of those work, the link shows as and the url generated is http://localhost:3000/portfolios/test?class=prev any ideas? – Richlewis Jan 12 '14 at 19:17
  • why does providing the link name make a difference? works by the way but was just wondering – Richlewis Jan 12 '14 at 19:30