Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Helper Method - HTML is displayed as plain text

Tags:

I have a helper method for my Rails app that returns a string with HTML code for a Google Groups subscription form. Unfortunately, it comes out on the page like plain text. How can I force it to render as HTML? Thanks in advance.

like image 600
SZH Avatar asked Jan 27 '11 20:01

SZH


People also ask

How do you use the helper method in Ruby on Rails?

A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.


1 Answers

The result of your helper needs to be marked as "html_safe" in Rails 3. Otherwise, the tags will be escaped.

def my_helper
  data = "<p>Hello!</p>"
  data.html_safe
end
like image 142
Dylan Markow Avatar answered Sep 21 '22 22:09

Dylan Markow