Under root:
1, install github markdown gem
gem install github-markdown
2, Add markdown gem into Gem file
root@ubuntuChef:/opt/ruby/user# vim Gemfile
gem 'github-markdown'
3, may need do:
bundle install
4, Define your markdown in your controller
I put MD file under app/assets/markdown folder
ang@ubuntuChef:/opt/ruby/user$ vim app/controllers/myusers_controller.rb
def markdown
#@myusers = Myuser.all
require 'github/markdown'
#require 'rdiscount'
mdfile = File.join(Rails.root, 'app', 'assets', 'markdown', 'test.md')
mymd = File.open(mdfile, 'rb') { |file| file.read }
@md = GitHub::Markdown.render(mymd)
#@md = RDiscount.new(mymd, :smart, :filter_html).to_html
end
5, update the view - DON'T forget RAW
root@ubuntuChef:/opt/ruby/user# vim app/views/myusers/markdown.html.erb
<h1>Markdown</h1>
<%= raw(@md) %>
No comments:
Post a Comment