首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将图标放在rails应用程序助手的链接旁边

如何将图标放在rails应用程序助手的链接旁边
EN

Stack Overflow用户
提问于 2022-07-21 16:48:29
回答 1查看 127关注 0票数 0

好的,这里有一个问题,我的application_helper.rb中有两个方法

代码语言:javascript
复制
def sidebar_link_to(body, url, icon)
html_options = {class: "sidebar-menu-item"}
link_to url, html_options do
  content_tag(:div, icon)
  content_tag(:span, body)
end
end

代码语言:javascript
复制
 def icon(filename, html_attributes = {})
begin
  path = "public/icons/#{filename}.svg"
  icon = Rails.root.join(path).read

  html = Nokogiri::HTML::DocumentFragment.parse icon
  svg = html.at_css "svg"

  html_attributes.each { |name, value| svg[name] = value }
rescue Errno::ENOENT
  html = "<!-- SVG #{path} not found -->"
end
raw html
end

这是我的html.erb代码

代码语言:javascript
复制
<%= sidebar_link_to "Maps", maps_path, icon("outline/map", class: "h-8 w-8 text-white") %>

我想我的图标显示旁边的地图链接,但不知怎的,它不工作的任何想法?

为了澄清,我希望帮助者的结果是这样的,但我无法找到解决方案:

代码语言:javascript
复制
<div class="sidebar-menu-item group flex items-center">
   <%= icon "outline/map", class: "h-8 w-8 text-white"%>
   <%= link_to "Maps", maps_path %>
</div>
EN

回答 1

Stack Overflow用户

发布于 2022-07-21 17:46:35

看看,它与您的问题有关。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73069932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档