有什么想法吗,为什么在Rails 7.1中,
<%= button_tag type: "submit", class: "inline-flex items-center justify-center gap-x-2 rounded-md bg-black px-3.5 py-2.5 w-full sm:w-min text-sm font-semibold text-zinc-200 hover:text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black" do %>
<span class="first-letter:capitalize"><%=t ("save") %></span>
<svg class="h-6 w-6" viewBox="0 0 24 24" stroke-width="1.5" fill="currentColor">
<path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm13.36-1.814a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z" clip-rule="evenodd" />
</svg>
<% end %>
渲染(如预期)
而如果我尝试使用一个helper方法来呈现相同的SVG,
<%= button_tag type: "submit", class: "inline-flex items-center justify-center gap-x-2 rounded-md bg-black px-3.5 py-2.5 w-full sm:w-min text-sm font-semibold text-zinc-200 hover:text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black" do %>
<span class="first-letter:capitalize"><%=t ("save") %></span>
<%= svg "check-circle-solid" %>
<% end %>
module ApplicationHelper
def svg(name)
file = Rails.root.join("app", "assets", "images", "#{name}.svg")
File.read(file).html_safe
end
end
它将
即使检查的代码看起来像
我尝试了几个浏览器(Firefox,Chrome,Safari),但问题仍然存在。
1条答案
按热度按时间gdrx4gfi1#
我有一个类似的方法来渲染svg,它需要路径的svg存储在资产文件夹.