没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > has-magic-columns |
has-magic-columns
|
0 | 0 | 3 |
贡献者 | 讨论 | 代码提交 |
HasMagicColumnsExtends ActiveRecord models and adds "magic" columns and attributes to a model. Model classes or instances can maintain completely unique and separate data and are able to access this data through the standard ActiveRecord style interface.
This is useful in multi-user or multi-account applications where each user can "customize" the attributes they would like to use without managing multiple schema or installations.
This plugin was written by and maintained by Brandon Keene, a professional Rails developer working in San Francisco, CA.
InstallationYou need to create table definitions for included column and attribute models.
Generate the migration using the included task:
rake has_magic_columns:db:createRun the standard migrate task to update your schema:
rake db:migrateYou're ready to start using Has Magic Columns!
- Brandon Keene
Exampleclass Person < ActiveRecord::Base
has_magic_columns
end
- Create a Person
@bob = Person.create(:email => "bob@example.com")
- Add some MagicColumns
@bob.magic_columns << MagicColumn.create(:name => "first_name")
@bob.magic_columns << MagicColumn.create(:name => "last_name")
@bob.magic_columns << MagicColumn.create(:name => "birthday", :datatype => "date")
- Give @bob some magic...
@bob.first_name = "Bob"
@bob.last_name = "Magic!"
@bob.birthday = Date.today
- Save @bob like normal
@bob.save
- Find @bob and inspect him
@bob = Person.find(@bob.id)
@bob.first_name #=> "Bob"
@bob.last_name #=> "Magic!"
@bob.birthday #=> #Inherit from "Template" ColumnsA child can "inherit" magic columns from its parent. You can use container models to provide a column template for contained objects. For example, an Account has_magic_columns and has_many :people. A Person inherits magic columns from its account:
class Person < ActiveRecord::Base
belongs_to :account
has_magic_columns :inherit => :account
endChildren people now all share the columns of their parent account. You don't need to use these magic columns on the Account of course. It's just a convenient and logical way to provide column templating.