Displaying 2 results from an estimated 2 matches for "attr_boolean".
2006 Jun 22
3
attr_boolean, a good idea?
Hello all,
I''ve recently been working with a model with a lot of boolean
attributes and I decided that it''s worth trying to implement a
attr_boolean function to cut down on the work. Something like
class User < ActiveRecord::Base
attr_boolean :contact_by_email, :display_real_name, :administrator
end
which would replace the hand written
class User < ActiveRecord::Base
def contact_by_email?
self.contact_by_email == 1
end...
2006 Jul 25
1
Node Attributes
...with a column in the database for every kind of type:
create_table :attributes do |t|
t.column :name, :string
t.column :type, :string
t.column :attr_string, :string
t.column :attr_text, :text
t.column :attr_integer, :integer
.
.
.
t.column :attr_boolean, :boolean
end
so to access the attribute would be through a function that does a
switch against the type.
now, which way would be better? the polymorphic way, or the single table
way?
--
Posted via http://www.ruby-forum.com/.