{"id":163,"date":"2006-09-10T20:35:28","date_gmt":"2006-09-11T01:35:28","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/09\/10\/updating-a-rails-plugin\/"},"modified":"2006-09-10T20:35:28","modified_gmt":"2006-09-11T01:35:28","slug":"updating-a-rails-plugin","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2006\/09\/10\/updating-a-rails-plugin\/","title":{"rendered":"Updating A Rails Plugin"},"content":{"rendered":"<p>I received an email asking me how to best enhance the comment model from the <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/06\/18\/acts-as-commentable-plugin\/\">Acts as Commentable<\/a> plugin.  It seems like a user of the plugin wants to add some <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/07\/29\/rails-model-validators\/\">rails validation<\/a> to the comment model class.  I have to admit that I would have just edited the plugin code in place, in fact this is what I have done in the past.  I didn&#8217;t want to brush off the question because it seems like a legitimate concern: how to add validation and methods to models provided by Ruby on Rails plugins?  Well, the answer is easy because in Ruby a class&#8217; implementation can be reopened at any time.  In this case we have to open the Comment class and evaluate new code:<\/p>\n<p>[source:ruby]<br \/>\nComment.class_eval do<br \/>\n  def my_new_method<br \/>\n    # do something<br \/>\n  end<br \/>\n  # do something else<br \/>\nend<br \/>\n[\/source]<\/p>\n<p>For this to work we need to place the above code in the application_helper.rb file.<\/p>\n<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/acts+as+commentable\" rel=\"tag\">acts as commentable<\/a>, <a href=\"http:\/\/technorati.com\/tag\/acts_as_commentable\" rel=\"tag\"> acts_as_commentable<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rails\" rel=\"tag\"> rails<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rubyonrails+ruby+on+rails\" rel=\"tag\"> rubyonrails ruby on rails<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rails+plugin\" rel=\"tag\"> rails plugin<\/a>, <a href=\"http:\/\/technorati.com\/tag\/rails+plugins\" rel=\"tag\"> rails plugins<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I received an email asking me how to best enhance the comment model from the Acts as Commentable plugin. It seems like a user of the plugin wants to add some rails validation to the comment model class. I have to admit that I would have just edited the plugin code in place, in fact [&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-2D","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/163"}],"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=163"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}