在Ruby on Rails 3中使用Twitter Bootstrap图标作为链接的最佳方式? [英] Best way to use Twitter Bootstrap Icons as Links in Ruby on Rails 3?

查看:176
本文介绍了在Ruby on Rails 3中使用Twitter Bootstrap图标作为链接的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Twitter Bootstrap提供的图标作为Rails 3中的链接的最好方法是什么?

What's the best way to use an icon provided by Twitter Bootstrap as a link in Rails 3?

目前,我使用它像粘贴的代码段,当我使用平板电脑查看网页时,图示不会显示。我确定有一个更好的方式使用Twitter Bootstrap图标作为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>


推荐答案

如果你构建一个这样的帮助:

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}
      ) %>

这篇关于在Ruby on Rails 3中使用Twitter Bootstrap图标作为链接的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆