RailsCasts Pro episodes are now free!

Learn more or hide this

SimplizIT's Profile

GitHub User: SimplizIT

Comments by

Avatar

Update for anyone using RedCarpet 3.0.0

Using this RailsCast, just change the helper method to this:

ruby
def markdown(blogtext)
    renderOptions = {hard_wrap: true, filter_html: true}
    markdownOptions = {autolink: true, no_intra_emphasis: true}
    markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(renderOptions), markdownOptions)
    markdown.render(blogtext).html_safe
 end

Then in view just use

ruby
<%= markdown(@blog.body) %>

Notice they changed to sets of hashes for options. One hash of options for the Redcarpet::Render::HTML.new(options hash here)
and the second options hash for the Redcarpet::Markdown.new(renderer(this is where the renderer goes), markdown hash here). To understand, here are both without removing options into two variables.

ruby
def markdown(blogtext)
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new({hard_wrap: true, filter_html: true}), {autolink: true, no_intra_emphasis: true})
  markdown.render(blogtext).htm_safe
end

Check their github site to find out which options belongs in which options hash.