css - 我将如何设置此 rails return 语句的内联样式?

标签 css ruby-on-rails inline

我试图将此返回语句设置为内联样式,但我输入的 HTML 只是显示在页面上。我将如何设置此内联样式?

def instruction
if self.o_connection.dongle? 
  return "Plug the #{self.o_cord.name} end of the <div class='greentext'>#{self.o_product.full_name}</div> into the #{self.i_product.full_name}."

最佳答案

这个方法似乎不在 Helper 中(它可能应该在)。无论如何,您可以使用 html_safe

def instruction
  if self.o_connection.dongle? 
    return "Plug the #{self.o_cord.name} end of the <div class='greentext'>#{self.o_product.full_name}</div> into the #{self.i_product.full_name}.".html_safe

另一种方法是在你的 View 中做这样的事情:

<%= raw(object.instruction) %>

无论哪种情况 - 我都会注意任何安全风险。看看Sanitize Helper .

关于css - 我将如何设置此 rails return 语句的内联样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18214237/

相关文章:

css - 调整窗口大小时,底部 div 的绝对位置不会改变

html - 在图像周围环绕文字,仅 css

ruby-on-rails - CSS 和 wicked_pdf 不起作用

c++ - 是否有任何编译器忽略有关默认内联函数的 C++ 标准?

html - 表在 th 和 td 中的空格后开始新行

javascript - div 窗口应该在顶部

ruby-on-rails - Rails - 如何使用 github 上的插件(如何安装、使用等)

ruby-on-rails - 很棒的嵌套集插件 - 如何在不同级别向树中添加新子项

f# - 强制执行显式类型参数

for-loop - 为什么简单的 for 循环表达式仅限于整数范围?