문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top