0

I have the following code in a Rails 3.2.1 helper that keeps escaping HTML even if i don't want it, and i can't figure out how to turn off the html escaping on this method (calling raw or html_safe doesn't work):

module OffersHelper
  def price_tag(amount)
    amount = amount.to_f
    floor = amount.floor
    cents = ((amount - amount.floor) * 100).to_i
    content_tag(:h2) do
      html = floor.to_s
      html << content_tag(:sup, cents) if cents > 0
      html
    end
  end
end

If i remove the nested content_tag (the sup tag), the html escaping is turned off...

1
  • Can you elaborate on how're you're calling raw/html_safe? And how you're rendering the string? Commented Mar 5, 2012 at 18:37

1 Answer 1

1

Try:

module OffersHelper
  def price_tag(amount)
    amount = amount.to_f
    floor = amount.floor
    cents = ((amount - amount.floor) * 100).to_i
    out = content_tag(:h2) do
      html = floor.to_s
      html << content_tag(:sup, cents) if cents > 0
      html
    end
    out.html_safe
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.