Acts as Addressable

Allows for addresses to be added to multiple and different models.

Resources

Install * Run the following command:

script/plugin install https://svn.nbarthelemy.com/acts_as_addressable
  • Create a new rails migration and add the following self.up and self.down methods

class AddAddressSupport < ActiveRecord::Migration def self.up create_table :addresses, :force => true do |t| t.column :addressable_id, :integer, :null => false t.column :addressable_type, :string, :null => false, :limit => 80 t.column :street1, :string, :null => false, :limit => 60 t.column :street2, :string, :limit => 60 t.column :city, :string, :null => false, :limit => 60 t.column :state, :string t.column :postal_code, :string, :null => false, :limit => 25 t.column :country, :string, :null => false, :limit => 60 end end

add_index :addresses, [:addressable_id, :addressable_type]
  add_index :addresses, :state    
  add_index :addresses, :country
end
def self.down
  drop_table :addresses
end
Usage * Make you ActiveRecord model act as addressable. class Model < ActiveRecord::Base acts_as_addressable end * Add a address to a model instance model = Model.new address = Address.new address.street1 = ‘Some Street’ address.street2 = ‘Some Street’ address.city = ‘Some City’ address.state = ‘CALIFORNIA’ address.country = ‘United States’ model.addresses << address * Each address reference addressable object model = Model.find(1) model.addresses.get(0).addressable model Credits

Xelipe – This plugin is heavily influced by Acts As Tagglable.

http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-addressable-plugin/ http://www.juixe.com/projects/acts_as_addressable

Tags

You need to Login to tag this item.