Let’s say you have a model Post title:string body:text.

In the form you already have a field <%= form.text_area :body %> and you don’t need to change anything there.

The thing about markdown is just about parsing text and displaying it with the propper formatting.

To parse text into markdown you will need the gem redcarpet.

Also, here’s a good markdown cheatsheet

Gemfile

gem "redcarpet"

application_helper.rb

def markdown(text)
  options = %i[
    hard_wrap autolink no_intra_emphasis tables fenced_code_blocks
    disable_indented_code_blocks strikethrough lax_spacing space_after_headers
    quote footnotes highlight underline
    ]
    Markdown.new(text, *options).to_html.html_safe
end

The options variable defines parsing settings that you use from Redcarpet.

Now in a view you can parse anything to markdown:

<%= markdown(@post.body) %>

Bonus - beautify your forms’ text input area:

<%= form.text_area :content, 
  style: "width: 100%", 
  rows: 8, 
  maxlength: 5000, 
  placeholder: 'User Markdown for formatting' 
%>