Sunday, February 28, 2010

Rails, RedCloth, textilize gotcha


# This doesn't work! It returns html in pure strings and not the html elements!

textilize @blog.content

# Need this extra step.

sanitize(textilize @blog.content)


**UPDATED**

The problem lies that Rails 3 ERB uses h() helper by default

<\%= xxx %>
<\%= h(xxx) %>
To get past this use context_tag() or raw()

xxx = content_tag(:p, "blah")
<\%= xxx %>

xxx = "<\p>blah<\/p>"
<\%= raw xxx %>

1 comment:

Plum & Ivory said...

What version of RedCloth were you using with Rails3 as when I use 4.2.3 or 4.2.2 I receive the following error:

uninitialized constant ActionView::Helpers::TextHelper::RedCloth

For you info, I installed RedCloth via bundler.

Thanks for you help!