Help us understand the problem. What is going on with this article?

Rails Markdown サンプルアプリ

More than 3 years have passed since last update.

環境
- Rails 4.1

サンプル
- https://github.com/usutani/note_md

参考
ASCIIcasts - “Episode 272 - RedcarpetでMarkdown”
masuidrive/open-wripe
vmg/redcarpet

実装

Markdownで記述できるメモアプリを作成したいと思います。

rails _4.1.1_ new note_md
cd note_md
rails g scaffold Page body:text
rake db:migrate

Markdownの処理に用いるgemを追加します。

Gemfile
# markdown
gem "redcarpet", "~> 2.3.0"
bundle install

Markdownの処理を追加します。

app/helpers/application_helper.rb
module ApplicationHelper  
  @@markdown = Redcarpet::Markdown.new Redcarpet::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: true

  def html(markdown)
    @@markdown.render(markdown).html_safe
  end
end
app/views/pages/show.html.erb
<%= html @page.body %>
usutani
好物は Ruby on Rails や iOS アプリの開発です。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした