Search code examples
ruby-on-railsrubytwitter-bootstrapsimple-form

how to add an bootstrap icon to simple_form's link_to_remove_association and link_to_add_association


Like the question says, I would like to put an icon into the link_to_add_association and link_to_remove_association s.

I'm using Ruby Rails, and simple_form, and I would like to put a bootstrap icon, rather than the words 'Add line', and 'Remove'.

This is what the code looks like. The f, in the code below is from a loop these are in.

<%= link_to_add_association 'Add line', f, :weeks %>

and

<%= link_to_remove_association 'Remove', f, :weeks %>

Thank you in advance!


Solution

  • link_to_add_association is an user defined helper method. In that method, we have link_to tag. Go to your link_to_add_association method(It may be in your helper), there should be a link_to tag. For example, In my link_to_add_association

    def link_to_add_association(f, association, **args)
    
    ###your code goes here 
    
    link_to('#', class: "xyx " , data: {id: xyz}) do 
        "<span class='fa fa-male fa-lg'>".html_safe
     end
    
    end
    

    I have used the font-awesome icon. You can use bootstrap icon instead.

    Reference: link_to