74
Go to list of users who liked
74
More than 5 years have passed since last update.
Rails Markdown サンプルアプリ
Last updated atPosted at 2014-05-26
環境
- Rails 4.1
サンプル
参考
ASCIIcasts - “Episode 272 - RedcarpetでMarkdown”
masuidrive/open-wripe
vmg/redcarpet
実装
Markdownで記述できるメモアプリを作成したいと思います。
rails _4.1.1_ new note_mdcdnote_mdrails g scaffold Page body:textrake db:migrate
Markdownの処理に用いるgemを追加します。
Gemfile
# markdowngem"redcarpet","~> 2.3.0"
bundleinstall
Markdownの処理を追加します。
app/helpers/application_helper.rb
moduleApplicationHelper@@markdown=Redcarpet::Markdown.newRedcarpet::Render::HTML,autolink:true,space_after_headers:true,no_intra_emphasis:true,fenced_code_blocks:true,tables:true,hard_wrap:true,xhtml:true,lax_html_blocks:true,strikethrough:truedefhtml(markdown)@@markdown.render(markdown).html_safeendend
app/views/pages/show.html.erb
<%= html @page.body %>
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme