daniel
daniel

Reputation: 3115

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

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

Upvotes: 1

Views: 2608

Answers (1)

DigitalRoss
DigitalRoss

Reputation: 146271

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) %>

Upvotes: 4

Related Questions