我有一個標籤標籤,其內容是從en.yml文件加載的。Rails轉義標籤標籤內的字符串
html.erb
<%=label_tag(:name, t(:name, scope:[:helpers, :form], name: person_name(person))).html_safe%>
PERSON_NAME是一個輔助並輸出來自輔助
persons_helper.rb
def person_name(person)
content_tag(:span,
formatted_name(person.name) || t("helpers.persons.default_name"),
class: 'name').html_safe
end
輸出串上噸方法傳遞的字符串並連接如下
en.yml
name: "Person Name: (%{name})"
我要輸出到像
<label for="person">
Person Name:
<span class='name> John Doe </span>
</label>
而是我得到
<label for="person">
Person Name:(<span class="name">John Doe</span>)
</label>
我明白,這得到了與html_safe做,原始的和逃避的字符串,但我無法讓它工作!
謝謝!