Rails link_to with fa_icon and html properties

Is there any way to use

Rails link_to function with fa_icon (FontAwesome gem)

as shown below?

 =link_to fa_icon("off"), destroy_user_session_path, :method=>'delete', {"data-toggle" => "tooltip", "data-original-title" => "Logout", "data-placement" => "bottom", :class => "btn btn-metis1 btn-sm"} 
+7
ruby ruby-on-rails ruby-on-rails-4
source share
3 answers

link_to (fa_icon "off"), other_options_go_here

This works for me.

+5
source share

This is usually normal.

 <%= link_to new_message_path, :class=> "you_class" do %> <i class="fa fa-envelope-o" aria-hidden="true" target="_blank"></i> <% end %> 

PS any other html properties can be placed as id, class, etc. And they noticed: it is better to place everything in one line, for example:

 <%= link_to new_message_path, :class=> "you_class" do %><i class="fa fa-envelope-o" aria-hidden="true" target="_blank"></i><% end %> 

else it issues a character to the right, immediately after the icon.

+1
source share

for attributes, data- * should be this way.

 =link_to fa_icon("off"), destroy_user_session_path, data: { "toggle" => "tooltip", "original-title" => "Logout", "placement" => "bottom" }, :method=>'delete', :class => "btn btn-metis1 btn-sm" 

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

0
source share

All Articles