Best way to use Twitter Bootstrap Icons as Links in Ruby on Rails 3?
css, icons, ruby-on-rails, ruby-on-rails-3, twitter-bootstrap
Solution
If you build a helper like this:
module BootstrapIconHelper
def icon_link_to(path, opts = {}, link_opts = {})
classes = []
[:icon, :blank].each do |klass|
if k = opts.delete(klass)
classes << "#{klass}-#{k}"
end
end
classes << "enlarge" if opts.delete(:enlarge)
opts[:class] ||= ""
opts[:class] << " " << classes.join(" ")
link_to content_tag(:i, "", opts), path, link_opts
end
end
you can write your links like this:
<%= icon_link_to(
vote_against_mission_mission_path(:id => mission.id),
{ :icon => "chevron-down", :blank => "vote", :enlarge => true },
{:method => :post}
) %>
<%= icon_link_to(
collect_mission_path(controller: "folders", action: "collect", id: mission.id),
{ :icon => "heart", :blank => "favorite", :enlarge => true, id: "action-centering}
) %>
Problem
What's the best way to use an icon provided by Twitter Bootstrap as a link in Rails 3? Currently, I am using it like the pasted snippet, but the icon doesn't display when I use my tablet to see the webpage. I'm sure there's a better way to use the Twitter Bootstrap Icons as links on Rails 3. ``` <%= link_to(vote_against_mission_mission_path(:id => mission.id), :method => :post) do %> <i class="icon-chevron-down blank-vote enlarge"></i> <% end %><br /> <%= link_to(collect_mission_path(controller: "folders", action: "collect", id: mission.id)) do %> <i class="icon-heart blank-favorite enlarge" id="actions-centering"></i> ```