Hi, I''m trying to use RedCloth class. I installed it today with gem. This is the sintax? html_content = RedCloth.new(@params[''media''][''description'']) html_content.to_html In the class doc have only the methods new and to_html, so how I convert a html in original string? Don''t have a method .to_str? http://redcloth.rubyforge.org/rdoc/classes/RedCloth.html Thank you. -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Hi Pedro, On 16.5.2005, at 22:07, Pedro Valentini wrote:> Hi, > > I''m trying to use RedCloth class. I installed it today with gem. > This is the sintax? > html_content = RedCloth.new(@params[''media''][''description'']) > html_content.to_html > In the class doc have only the methods new and to_html, so how I > convert a html in original string? Don''t have a method .to_str?I don''t think you can convert from html to textile (or Markdown). You should always store both the original string and the converted html. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine escreveu:> Hi Pedro, > > On 16.5.2005, at 22:07, Pedro Valentini wrote: > >> Hi, >> >> I''m trying to use RedCloth class. I installed it today with gem. >> This is the sintax? >> html_content = RedCloth.new(@params[''media''][''description'']) >> html_content.to_html >> In the class doc have only the methods new and to_html, so how I >> convert a html in original string? Don''t have a method .to_str? > > > I don''t think you can convert from html to textile (or Markdown). You > should always store both the original string and the converted html. > > //jarkkoThank you. The code worked with: html_content = RedCloth.new(@params[''media''][''description'']).to_html And I will store the original code only, and when will need converto to html :) -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On 16.5.2005, at 22:27, Pedro Valentini wrote:> Thank you. > The code worked with: > html_content = RedCloth.new(@params[''media''][''description'']).to_html > And I will store the original code only, and when will need converto > to html :)You might want to store the converted html, too, and do the conversion already when an object is saved. That way you don''t need to do the conversion every time a page (or a news or whatever) is requested, which happens a lot more often that the save. You can use a before_save filter for this: class News < ActiveRecord::Base before_save :transform_html private def transform_html t = RedCloth.new(self.body) t.hard_breaks = true self.body_html = t.to_html end end //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails