Acts As Phoneable
Allows for phone numbers to be added to multiple and different models.
Resources
Install * Run the following command:
script/plugin install https://svn.nbarthelemy.com/svn/acts_as_phoneable
- Create a new rails migration and add the following self.up and self.down methods
class AddPhoneNumberSupport < ActiveRecord::Migration def self.up create_table :phone_numbers do |t| t.column :phoneable_id, :integer, :null => false t.column :phoneable_type, :string, :limit => 80, :null => false t.column :number_type, :string, :limit => 25, :null => false t.column :number, :string, :limit => 25, :null => false t.column :ext, :string, :limit => 6 end end
add_index :phone_numbers, [:phoneable_id, :phoneable_type, :number_type, :number, :ext]
end
def self.down
drop_table :phone_numbers
end
Usage
* Make you ActiveRecord model act as phone_numberable.
class Model < ActiveRecord::Base
acts_as_phoneable
end
* Add a phone number to a model instance
model = Model.new
phone_number = Comment.new
phone_number.number_type = ‘HOME’
phone_number.number = ‘5555555555’
phone_number.ext = ‘1234’
model.phone_numbers << phone_number
* Each phone_number reference phone_numberable object
model = Model.find(1)
model.phone_numbers.get(0).phoneable model
Credits
Xelipe – This plugin is heavily influced by Acts As Tagglable.
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-phone_numberable-plugin/ http://www.juixe.com/projects/acts_as_phone_numberable
- Repository Path: https://svn.nbarthelemy.com/acts_as_phoneable/