Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top