virtual_attribute 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -0
- data/lib/virtual_attribute/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
Adds a virtual attribute to models, that plays nice with forms etc
|
2
|
+
|
3
|
+
|
4
|
+
example:
|
5
|
+
|
6
|
+
class MyModel < ActiveRecord::Base
|
7
|
+
virtual_attribute :foo, :boolean => true, :attr_type => :attr_accessible
|
8
|
+
virtual_attribute :bar, :boolean => true, :attr_type => :attr_accessible
|
9
|
+
end
|
10
|
+
|
11
|
+
params = {:foo => '1', :bar => 'false'}
|
12
|
+
thing = MyModel.new(params)
|
13
|
+
|
14
|
+
thing.foo #=>true
|
15
|
+
thing.bar #=> false
|
16
|
+
|
17
|
+
|
18
|
+
Virtual attributes can be set to :boolean => true
|
19
|
+
|
20
|
+
- This will parse ['yes', 'true', '1', 1] to be true
|
21
|
+
- and ['no', 'false', '0', 0] to be false
|
22
|
+
- otherwise will be nil
|
23
|
+
- this allows them to be used transparently with checkboxes etc in forms
|
24
|
+
|
25
|
+
If using attr_accessible in your model, the virtual attribute should be added to the list to, or you can pass:
|
26
|
+
|
27
|
+
:attr_type => :attr_accessible
|
28
|
+
|
29
|
+
as an option as shown above to have it done for you
|
30
|
+
|
31
|
+
Will document better later, until then:
|
32
|
+
phil at latentflip dot com
|
33
|
+
|
34
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Philip Roberts
|
@@ -18,7 +18,7 @@ date: 2010-08-09 00:00:00 +01:00
|
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description:
|
21
|
+
description: A virtual attribute builder for models that plays nice with webforms.
|
22
22
|
email:
|
23
23
|
- phil@floatapp.com
|
24
24
|
executables: []
|