好的,这里有一个问题,我的application_helper.rb中有两个方法
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和
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代码
<%= sidebar_link_to "Maps", maps_path, icon("outline/map", class: "h-8 w-8 text-white") %>我想我的图标显示旁边的地图链接,但不知怎的,它不工作的任何想法?
为了澄清,我希望帮助者的结果是这样的,但我无法找到解决方案:
<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>发布于 2022-07-21 17:46:35
看看这,它与您的问题有关。
https://stackoverflow.com/questions/73069932
复制相似问题