Topic: How do you add a value to a table using the 'back door'?

I'm attempting to add another field to the Tag.model in the acts_as_taggable plugin. The code in the tag.rb is too complicated for me decypher and I thought that if I could update the model so that an instance field is added upon creation of each new record, that I'd be in clover!
I've read about attributes and adding them as methods to a table model, but I've never seen how an attribute is added upon creation of the original instance (or row)?
I expect the logic will be something like;
def addnewvalue
  integerfieldname = @instance.integer
end
I hope you see the foundation of my question is "How do you get this method to fire upon creation of the instance record, without going through the controller logic?"
Thank you,
Kathy

Re: How do you add a value to a table using the 'back door'?

To trigger methods on certain events, including record creation, you can use callbacks.
http://api.rubyonrails.org/classes/Acti … backs.html

Create a migration file and add the new column to the tag table.


As an example, assuming you have a "rating" field for the tags table:

class Tag < ActiveRecord::Base
  before_create :set_default_rating

  protected

  def set_default_rating
    rating = 3
  end
end

Vincent Woo Ruby on Rails Blog