我想在管理员中显示一个字段,用户可以在其中选择一些字体真棒图标。所以我现在所做的是:
field :icon, :enum do
enum do
Navitem.available_icons
end
end
def self.available_icons
[
['<i class="fa fa-glass" aria-hidden="true"></i>',"fa-glass"],
["<i class='fa fa-music'></i>","fa-music"],
["<i class='fa fa-search'></i>","fa-search"]
]
end
但HTML会被转义并显示为文本。有没有办法我可以输出HTML而不逃避它?
关于马库斯
你可以使用html_safe
def self.available_icons
[
['<i class="fa fa-glass" aria-hidden="true"></i>'.html_safe, "fa-glass"],
["<i class='fa fa-music'></i>".html_safe, "fa-music"],
["<i class='fa fa-search'></i>".html_safe, "fa-search"]
]
end