Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/latentflip/virtual_attribute
Virtual Attributes that play nice with forms & active_record
https://github.com/latentflip/virtual_attribute
Last synced: 30 days ago
JSON representation
Virtual Attributes that play nice with forms & active_record
- Host: GitHub
- URL: https://github.com/latentflip/virtual_attribute
- Owner: latentflip
- License: mit
- Created: 2010-08-09T21:06:13.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-09-10T09:32:46.000Z (about 14 years ago)
- Last Synced: 2024-10-03T23:45:41.459Z (about 1 month ago)
- Language: Ruby
- Homepage: http://rubygems.org/gems/virtual_attribute
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this 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
endparams = {:foo => '1', :bar => 'false'}
thing = MyModel.new(params)
thing.foo #=>true
thing.bar #=> falseVirtual 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 formsIf 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 youWill document better later, until then:
phil at latentflip dot com