rails 3 似乎逃避了一切,包括 html。我尝试过使用 raw() 但它仍然转义 html。有解决方法吗?这是我正在使用的助手 (/helpers/application_helper.rb):
module ApplicationHelper
def good_time(status = true)
res = ""
if status == true
res << "Status is true, with a long message attached..."
else
res << "Status is false, with another long message"
end
end
end
我使用以下代码在我的 View 中调用助手:
<%= raw(good_time(true)) %>
最佳答案
您可以像这样使用.html_safe
:
def good_time(status = true)
if status
"Status is true, with a long message attached...".html_safe
else
"Status is false, with another long message".html_safe
end
end
<%= good_time(true) %>
关于ruby-on-rails - 不要在 ruby on Rails 中转义 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3932267/