Updating A Rails Plugin

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 this is what I have done in the past. I didn’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’ implementation can be reopened at any time. In this case we have to open the Comment class and evaluate new code:

Comment.class_eval do
def my_new_method
# do something
end
# do something else
end

For this to work we need to place the above code in the application_helper.rb file.

Technorati Tags: , , , , ,

Related posts:

  1. Rails Plugin Tutorial
  2. Acts As Commentable Plugin
  3. Acts As Voteable Rails Plugin
  4. Riff Rails Plugin
  5. Graphs Rails Plugin
  6. Rails PDF Plugin


Leave a Reply