{"id":127,"date":"2006-07-05T08:16:46","date_gmt":"2006-07-05T13:16:46","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/07\/05\/acts-as-blog-plugin\/"},"modified":"2006-07-05T08:16:46","modified_gmt":"2006-07-05T13:16:46","slug":"acts-as-blog-plugin","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2006\/07\/05\/acts-as-blog-plugin\/","title":{"rendered":"Acts As Blog Plugin"},"content":{"rendered":"<p>The Ruby on Rails plugin acts_as_blog does not make your <b>ActiveRecord<\/b> model into a blog&#8230;  The acts_as_blog plugin helps your model by converting simple text to HTML formatted text.  You can use acts_as_blog in blogs, as the name alludes to, or in a wiki-like system.  Acts As Blog currently supports <b>text-to-HTML<\/b> formats <a href=\"http:\/\/www.textism.com\/tools\/textile\/\">Textfile<\/a> via the RedCloth gem, <a href=\"http:\/\/daringfireball.net\/projects\/markdown\/\">Markdown<\/a> via the BlueCloth gem, and <a href=\"http:\/\/daringfireball.net\/projects\/smartypants\/\">SmartyPants<\/a> via the RubyPants gem.  You need to install any one, or all, of these gems before you use this plugin.<\/p>\n<pre>\ngem install RedCloth\ngem install BlueCloth\ngem install RubyPants\n<\/pre>\n<p>To install the plugin just run this script:<\/p>\n<pre>\nscript\/plugin install http:\/\/svn.recentrambles.com\/plugins\/acts_as_blog\n<\/pre>\n<p>In your model you need to call the acts_as_blog method just like any other ActiveRecord plugin.  For this plugin you will also need to do some additional processing before the model is persisted into the database.<\/p>\n<pre>\nclass Post &lt; ActiveRecord::Base\n  acts_as_blog\n\n  before_save :txt_to_html\n\n  def txt_to_html\n    self.post = Post.convert_to_html(self.raw_post, 'textile')\n  end\nend\n<\/pre>\n<p>You can switch &#8216;markdown&#8217; or &#8216;smartypants&#8217; as the text-to-HTML format in the convert_to_html method by replacing &#8216;textile&#8217;.  Also notice that in the txt_to_html method a field raw_post is converted to HTML and copied to the field post.  If you use code similar to this you will need a raw_post and a post column in your database posts table.  The data in the post column of the posts database will have the HTML formatted text while the raw_post column will keep the original unformatted data.  Using the acts_as_blog plugin in this fashion you will stash the model data and the presentation data in the database.<\/p>\n<p>You can also use BlueCloth, RedCloth, and\/or RubyPants without using this plugin.  Personally, I would store the raw text in database and only convert it to HTML in the view without using the plugin.<\/p>\n<pre>\n&lt;%= BlueCloth.new(\"### HELLO\\nTECHKNOW\\n\").to_html %&gt;\n<\/pre>\n<p>I recommend you use a helper function that will do the conversion so that you can switch between the different text-to-HTML formats more easily.<\/p>\n<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/ruby\" rel=\"tag\">ruby<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rails\" rel=\"tag\">  rails<\/a>, <a href=\"http:\/\/technorati.com\/tag\/ruby+on+rails\" rel=\"tag\">  ruby on rails<\/a>, <a href=\"http:\/\/technorati.com\/tag\/plugin\" rel=\"tag\">  plugin<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rails+plugin\" rel=\"tag\">  rails plugin<\/a>, <a href=\"http:\/\/technorati.com\/tag\/activerecord\" rel=\"tag\"> activerecord<\/a>, <a href=\"http:\/\/technorati.com\/tag\/acts_as_blog\" rel=\"tag\"> acts_as_blog<\/a>, <a href=\"http:\/\/technorati.com\/tag\/textile\" rel=\"tag\"> textile<\/a>, <a href=\"http:\/\/technorati.com\/tag\/smartypants\" rel=\"tag\"> smartypants<\/a>, <a href=\"http:\/\/technorati.com\/tag\/markup\" rel=\"tag\"> markup<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Ruby on Rails plugin acts_as_blog does not make your ActiveRecord model into a blog&#8230; The acts_as_blog plugin helps your model by converting simple text to HTML formatted text. You can use acts_as_blog in blogs, as the name alludes to, or in a wiki-like system. Acts As Blog currently supports text-to-HTML formats Textfile via the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[22,3],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-23","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/127"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}