Rails has a built in textilize() method but it by default treats a new line as a BR tag. Which is really lame and annoying.
The code the Rails textilize() method uses is:
textilized = RedCloth.new(text, [ :hard_breaks ])
What this does is causes some textile text like this
h1. Birds I know all about birds. They have wings. Birds eat worms.
into this HTML
<h1>Birds</h1> <br/> I know all about birds. They have wings. <br/> Birds eat worms.
Not good code at all!
The Solution
Rails by default isn’t behaving how we need it so we have to override the method Rails uses. We do this by creating our own textilize() method in our application helper that doesn’t include the [:hard_breaks] option Rails does.
module ApplicationHelper
def textilize(text) # overriding Rails method to remove hardbreaks
if text.blank?
""
else
textilized = RedCloth.new(text).to_html
end
end
end
So there you have it. Call the Textilize method now and you’re Textile will be nicely formatted with paragraphs.