eran
eran

Reputation: 15136

Printing HTML tags into Ruby on Rails

I'm trying to print out an HTML table in Ruby on Rails

<h1>Welcome</h1>
<p>
<%=     sprintf print_series(@myTable) %>
</p>

*The Helper:

module WelcomeHelper
    def print_series(graph)     
        res = '<table border="2">'
        graph.each {
            |point|
            res = res + new_row(new_cell(point["date"]) + new_cell(point["value"]))
        }
        res << '</table>'
        return res.html_safe
    end
end

Nothing seems to work, I keep getting the HTML tags escaped, such that I can "see" the HTML on my browser, instead of seeing a table. What am I doing wrong?

Upvotes: 0

Views: 1758

Answers (1)

Larry K
Larry K

Reputation: 49104

Rails 3 automatically escapes html in output.

There are a number of ways to tell it not to do so for selected output.

Here's a Railscast about the subject

Added Drop the sprintf:

<%= print_series(@myTable) %>

Upvotes: 2

Related Questions