No commit activity in last 3 years
No release in over 3 years
A virtual attribute builder for models that plays nice with webforms.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Adds a virtual attribute to models, that plays nice with forms etc

example:

class MyModel < ActiveRecord::Base
  virtual_attribute :foo, :boolean => true, :attr_type => :attr_accessible
  virtual_attribute :bar, :boolean => true, :attr_type => :attr_accessible
end

params = {:foo => '1', :bar => 'false'}
thing = MyModel.new(params)

thing.foo #=>true
thing.bar #=> false

Virtual attributes can be set to :boolean => true

  • This will parse ['yes', 'true', '1', 1] to be true
  • and ['no', 'false', '0', 0] to be false
  • otherwise will be nil
  • this allows them to be used transparently with checkboxes etc in forms

If using attr_accessible in your model, the virtual attribute should be added to the list to, or you can pass:

:attr_type => :attr_accessible 

as an option as shown above to have it done for you

Will document better later, until then: phil at latentflip dot com