Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 924
user425766 Avatar asked Aug 26 '10 19:08

user425766


3 Answers

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 %>
like image 82
VvDPzZ Avatar answered Nov 19 '22 04:11

VvDPzZ


You can use RDiscount https://github.com/rtomayko/rdiscount

like image 3
Sohan Avatar answered Nov 19 '22 05:11

Sohan


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.

like image 2
Simone Carletti Avatar answered Nov 19 '22 05:11

Simone Carletti