Frage

So I have this code that I want to convert to rails using link_to:

<a href="#">
 <i class="icon-caret-right"></i>
 <span>Home</span>
</a>

Giving a nice formatted space in between: > Home

the closest code to get the same result that I have tested with is:

<%= link_to "Factcars", root_path, class: "icon-caret-right" %>

Which gives me (without a space in between): >Home

<i class="icon-caret-right" ><%= link_to content_tag(:span, "Factcars"), root_path %></i>

Gives same result: >Home

Is there a correct way to format this code?

War es hilfreich?

Lösung

pass block in link_to

<%= link_to "#" do %>
  <i class="icon-caret-right"></i>
   <span>Home</span>
<% end %>

depending upon link and name , modify the above method.

Andere Tipps

navigation helper defines a simple method for link_to_with_icon in the module of Spree::Admin gem

#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object

you can redefine the method in your own helper

def link_to_with_icon(icon_name, text, url, options = {})
  options[:class] = (options[:class].to_s + " fa fa-#{icon_name} icon_link with-tip").strip
  options[:class] += ' no-text' if options[:no_text]
  options[:title] = text if options[:no_text]
  text = options[:no_text] ? '' : raw("<span class='text'>#{text}</span>")
  options.delete(:no_text)
  link_to(text, url, options)
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top