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:
[source:ruby]
Comment.class_eval do
def my_new_method
# do something
end
# do something else
end
[/source]
For this to work we need to place the above code in the application_helper.rb file.
Technorati Tags: acts as commentable, acts_as_commentable, rails, rubyonrails ruby on rails, rails plugin, rails plugins