I've got a function in my ApplicationHelper, as well as an exact duplicate in a controller for prerendering. Prerendering creates the links the way I want, with target="_blank", but rendering on the spot does not. My code is as follows:
require 'redcarpet'
module ApplicationHelper
def markdown(text)
rndr = Redcarpet::Render::HTML.new(:link_attributes => Hash["target" => "_blank"])
markdown = Redcarpet::Markdown.new(
rndr,
:autolink => true,
:space_after_headers => true
)
return markdown.render(text).html_safe
end
end
Running this in the rails console also renders links as normal, without the link attributes. Identical code in my controller works as expected.