【问题标题】:How to add bootstrap glyphicons into ruby on rails link_to如何在rails link_to上将引导字形添加到ruby中
【发布时间】:2017-08-19 16:35:05
【问题描述】:

我想在我的 ruby​​ on rails 应用程序中有一个指向某个页面的链接,并且我希望它显示为一个字形图标(“glyphicon glyphicon-eye-open”),而不是“显示”。请帮我。这是我的链接:

请帮助我。提前致谢。

【问题讨论】:

  • 你安装了 bootstrap gem 吗?

标签: ruby-on-rails glyphicons


【解决方案1】:

您可以将块传递给 link_to(如果您想使用图标标签等)。

以 FontAwesome 为例,

link_to LINK_URL do
   fa_icon 'bathtub'
end

https://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to

【讨论】:

    【解决方案2】:

    如果您想使用引导程序显示字形图标,请使用此代码

    <%= link_to '<i class="glyphicon glyphicon-eye-open"></i>'.html_safe, show_schedule_in_teams_path, :class => 'btn btn-mini btn-danger'  %>
    

    【讨论】:

    • 您是遇到错误还是图标没有显示?顺便说一句,我正在使用 bootstrap gem 来回答您的问题,您在使用 bootstrap 吗?
    • 图标不显示。我必须先安装引导 gem 吗?抱歉,我是 Rails 新手。
    • 我的建议是,如果你想从 bootstrap 中使用 glyphicon,你必须使用 bootstrap gem 之一,你可以通过这个链接跟进 github.com/twbs/bootstrap-sass
    【解决方案3】:

    首先,确保您的 rails 应用程序上安装了引导程序。这样做

    1. gem 'bootstrap-sass' 添加到您的Gemfile
    2. 执行bundle install
    3. *= require bootstrap_framework 添加到您的application.css
    4. 重新启动您的 Rails 应用程序服务器

    之后,您应该可以使用以下代码:

    <%= link_to '<span class="glyphicon glyphicon-eye-open"></span>'.html_safe, show_schedule_in_teams_path %>
    

    【讨论】:

      猜你喜欢
      • 2014-07-19
      • 1970-01-01
      • 2018-10-18
      • 2016-02-10
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多