Rendering markdown text in Rails 3
I want to convert markdown to html. In my views I have markdown(some_text_variable)
but I get the error undefined method markdown
.
I added require 'BlueCoth'
to enviroment.rb and 开发者_如何转开发I installed the BlueCloth gem. Can anybody help me?
In your Gemfile:
gem 'bluecloth'
and don't forget to run
bundle install
when you need to convert markdown to html, simply use:
markdown = BlueCloth.new(some_text_variable).to_html
You can use it in a view:
<%= markdown.html_safe %>
You can use RDiscount https://github.com/rtomayko/rdiscount
The #markdown
helper was removed in Rails 3.
You can copy & paste the code from the commit or use a third party Gem, like formatize. You will also have to include the required BlueCloth
/RedCloth
/etc gem in your Gemfile
.
I'd recommend against bluecloth as it doesn't look like it's being upkept that well.
Best thing I've found out there as of now (summer 2013) is the Redcarpet gem: https://github.com/vmg/redcarpet
Try adding the following to your environment.rb
instead of the require:
config.gem 'BlueCloth', :lib => 'bluecloth'
In Rails 3, this would be in the Gemfile:
gem 'bluecloth'
The gem is called BlueCloth, but the .rb file that gets required is all lowercase.
Make sure you restart rails after adding the config.gem line.
精彩评论