Feeds:
Posts
Comments

Archive for May 26th, 2011

Greetings!

Today when i was working with helper methods for a ruby on rails project, i faced a problem of not rendering HTML tags in View

Instead it rendered as a String.

For example, the actual scenario is,

I had the following code in helper module

def show_list(num, page=nil)
..........
..........
content = []
for i in collection
content << "<li> #{i.name} </li>"
end
.........
.........
end

Inside view when i called this method

<%=  show_list(25) %>

I got the output as a string, “<li>actual data goes here</li>”, not interpreting the HTML tags

Then after surfing for nearly a couple of hours, i came to know that its a wrong way of calling the method in View

The right way  is to prefix the method using raw helper method

Correct way


<%= raw show_list(25) %>

Now the view displays the data as a list item 🙂

Read Full Post »