我有一个选择框来显示列表出货详情。 当用户将鼠标悬停在每个选项上时,我需要显示每个选项的预览以及更多详细信息。使用rails标签解决这个问题
<%= select_tag 'cashed_shipment', options_from_collection_for_select(@cached_shipments,:id,:cached_shipment_detail,prompt: true) %>
在模型中,我写了一个方法返回每个选项的标记
def cached_shipment_detail
"<div class= 'dropdown-option'>
<div class ='dropdown-header'> #{vessel_name} | #{voyage_number} | #{loading_date}</div>
<div class = 'dropdown-preview'> more detail preview here </div>
</div>
端
但是上面的脚本打印为文本而不是标记,我怎么能解决这个问题。
答案 0 :(得分:0)
使用:html_safe
!
def cached_shipment_detail
"<div class= 'dropdown-option'>
<div class ='dropdown-header'> #{vessel_name} | #{voyage_number} | #{loading_date}</div>
<div class = 'dropdown-preview'> more detail preview here </div>
</div>".html_safe
end
答案 1 :(得分:0)
尝试以下
def cached_shipment_detail
html = <<-HTML
<div class = "dropdown-option">
<div class = "dropdown-header"> #{vessel_name} | #{voyage_number} | #{loading_date}</div>
<div class = "dropdown-preview"> more detail preview here </div>
</div>
HTML
html.html_safe
end
希望能提供帮助