how do display html + css tags in a rails helper method

别等时光非礼了梦想. 提交于 2019-12-11 04:14:44

问题


I am trying to write something like this, but it display me the whole string. Not the formatted "Today!". Feel free to tune my method :) thanks

def days_left(deadline)
  (if deadline.date-Date.today == 0
    "<strong>Today!</strong>"
  elsif deadline.date-Date.today < 1
    "<div class='expired'>Overdue</div>"
  else
    (deadline.date-Date.today).to_i
  end)
end

回答1:


def days_left(deadline)
  (if deadline.date-Date.today == 0
    "<strong>Today!</strong>"
  elsif deadline.date-Date.today < 1
    "<div class='expired'>Overdue</div>"
  end).html_safe
end

Or, display it in the view with

<%= raw days_left(d) %>


来源:https://stackoverflow.com/questions/4741690/how-do-display-html-css-tags-in-a-rails-helper-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!