結論
1,2,3を導入すればいい
1. gem 'redcarpet'
2.
module MarkdownHelper
def markdown(text)
options = {
filter_html: true,
hard_wrap: true,
space_after_headers: true,
with_toc_data: true
}
extensions = {
autolink: true,
no_intra_emphasis: true,
fenced_code_blocks: true,
tables: true
}
renderer = Redcarpet::Render::HTML.new(options)
markdown = Redcarpet::Markdown.new(renderer, extensions)
markdown.render(text).html_safe
end
end
3 .
<%= markdown(@article.body).html_safe %>
参考
https://musicamusik.hatenablog.com/entry/2018/06/09/181439
エラーが出た場合
gemlockを確認するとgem 'redcarpet'がバージョン指定されている可能性があります。自分の場合、gemlockのバージョン指定を削除してbundle updateすることで解決しました。