Search code examples
ruby-on-railslink-to

Rails link_to_if Class Doesnt Display Correctly


For the life of me, i cant figure out why this problem is happening. I used the link_to helper all the time, but iv only used the link_to_if helper a few times, and this time I cant get the link to take a CSS class.

Here's my link

<%= link_to_if(step.sequence > 1, raw('<i class="icon-chevron-up"></i>'), url_for(:controller => :test_steps, :action => :update_sequence, :direction => 'up', :id => step.id, :test_script_id => @test_script), { :class => 'btn btn-mini' })%>

The image displays, with no link as expected, but the CSS class defined at the end does not, instead it just has no class. This is the same format I use in all my link_to helpers.

Can anyone explain why?


Solution

  • Using link_to_if, only the name --in your case the result of raw('<i class="icon-chevron-up"></i>')-- will be returned if the condition fails. All options that would otherwise apply to the link tag will be ignored.

    See the source.