freeform 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDBmMWJjMDZmMGU4MDBlNzgxMTg3ZmNhYWExMmVlZWNlY2RjYTQ5Mg==
5
+ data.tar.gz: !binary |-
6
+ MzNiYjRlODQ0YTM2ZjIxMGQxMTljZjY0NzQ5MmU4OTI1MzJjNjA0NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2I0OTUxZWEzYjk0OGFiNzljYzBlZDQ0MWFjYTNkZjMxYWY2MjMzMTU0N2U4
10
+ ODAyNmU1M2NiYTAyNjI1YjRmMmVkOTZhNGYxNDA5NmU0YWUyMjJiNzgwN2U4
11
+ Y2IwYWE3NmI4NDIzMTUwZDE4NzM0ZWFiMGI0MzA1OTM4MzEwZGM=
12
+ data.tar.gz: !binary |-
13
+ MzYzMDFlNWYyMTM5YzVjOWQ0NGMwMTMzYzJlMzAyNjczZjgyMzdiMGZlYTE0
14
+ OWQyMDM2YjY3NDhmYzU2ZmE3NDUzNjRhM2MyOTBlMzUzNGRiZTQ0ZjkxZDll
15
+ ZjgwMWIyMjNmMjkyMGFhOGNkYzIxNDk4MDQ4ZWQzODBmNjllZDc=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freeform (1.0.0)
4
+ freeform (1.0.1)
5
5
  activemodel
6
6
  formtastic
7
7
  nested_form (~> 0.3.2)
data/README.md CHANGED
@@ -6,7 +6,9 @@ FreeForm is a gem designed to give you total control over form objects, allowing
6
6
  * Simply composing multi-model forms
7
7
  * Removing the ugliness of `accepts_nested_attributes_for`
8
8
 
9
- FreeForm is designed primarily with Rails in mind, but it should work on any Ruby framework. FreeForm is compatible with most form gems, including simpleform, formbuilder, and Ryan Bate's nested_form gem.
9
+ FreeForm is designed primarily with Rails in mind, but it should work on any Ruby framework. FreeForm is compatible with most form gems, including simpleform, and formbuilder
10
+
11
+ **FreeForm will not work with Ryan Bate's nested_form gem, but provides its own identical behavior**
10
12
 
11
13
  ## Installation
12
14
 
@@ -79,7 +81,7 @@ FreeForm doesn't assume a lot, so you need to tell it:
79
81
  * The names of the models it's going to be mapping (specified as `form_model` or `form_models`)
80
82
  * The properties of the form, and which model they map to (specified as `property` or `properties`). Properties that don't map to a model are considered to be just form attributes.
81
83
  * How to validate, if at all (see below)
82
-
84
+
83
85
  ```ruby
84
86
  class RegistrationForm < FreeForm::Form
85
87
  form_models :user, :address
@@ -171,22 +173,22 @@ class UserForm < FreeForm::Form
171
173
  property :username, :on => :user
172
174
  property :email, :on => :user
173
175
  property :current_password
174
-
176
+
175
177
  # But you can also validate in the form itself!
176
- validates :email, :presence => true
178
+ validates :email, :presence => true
177
179
  validate :valid_current_password
178
-
180
+
179
181
  def valid_current_password
180
182
  user.password == current_password
181
183
  end
182
184
  end
183
185
  ```
184
- Personally, I use validations in both places. My domain models have their own validations, which I use for things that are universally true of that model (e.g. email is correctly formatted). Some forms have validations though that are specific to that form, and they live in the form itself (see above example with `current_password`)
186
+ Personally, I use validations in both places. My domain models have their own validations, which I use for things that are universally true of that model (e.g. email is correctly formatted). Some forms have validations though that are specific to that form, and they live in the form itself (see above example with `current_password`)
185
187
 
186
188
  ## Nesting Forms
187
189
 
188
190
  One of the benefits of forms objects is that you don't have to mess with models accepting nested attributes.
189
- But sometimes, you need to be able to support a collection of unknown size (e.g. a user with many phone numbers).
191
+ But sometimes, you need to be able to support a collection of unknown size (e.g. a user with many phone numbers).
190
192
  Since FreeForm makes no assumptions about your domain models, we nest forms themselves.
191
193
 
192
194
  ```ruby
@@ -195,9 +197,9 @@ class UserForm < FreeForm::Form
195
197
 
196
198
  property :username, :on => :user
197
199
  property :email, :on => :user
198
-
200
+
199
201
  has_many :phone_numbers, :class => PhoneNumberForm, :default_initializer => :phone_initializer
200
-
202
+
201
203
  def phone_initializer
202
204
  { :phone => user.phone_numbers.build }
203
205
  end
@@ -232,9 +234,9 @@ class UserForm < FreeForm::Form
232
234
 
233
235
  property :username, :on => :user
234
236
  property :email, :on => :user
235
-
237
+
236
238
  has_many :phone_numbers, :class => PhoneNumberForm, :default_initializer => :phone_initializer
237
-
239
+
238
240
  def phone_initializer
239
241
  { :phone => user.phone_numbers.build }
240
242
  end
@@ -274,7 +276,7 @@ class MyScope::UserForm < FreeForm::Form
274
276
  property :email, :on => :user
275
277
  end
276
278
  ```
277
- Would render with HTML input fields like
279
+ Would render with HTML input fields like
278
280
  `<input id="user_email" ... name="user[email]"></input>` instead of
279
281
  `<input id="my_scope_user_form_email" ... name="my_scope_user_form[email]"></input>`
280
282
 
@@ -3,15 +3,14 @@ module FreeForm
3
3
  def self.included(base)
4
4
  base.extend(ClassMethods)
5
5
  end
6
-
6
+
7
7
  module ClassMethods
8
8
  def form_input_key(name)
9
9
  constant = name.to_s.camelize
10
- Object.const_set(constant, Module.new) unless const_defined?(constant)
11
10
  define_singleton_method(:model_name) do
12
- ActiveModel::Name.new(constant.constantize)
11
+ ActiveModel::Name.new(self, nil, constant)
13
12
  end
14
13
  end
15
14
  end
16
15
  end
17
- end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Freeform
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
Binary file