simple_form 2.1.3 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (72) hide show
  1. data/CHANGELOG.md +6 -54
  2. data/README.md +129 -111
  3. data/lib/generators/simple_form/install_generator.rb +4 -4
  4. data/lib/generators/simple_form/templates/README +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +8 -11
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  8. data/lib/simple_form.rb +31 -47
  9. data/lib/simple_form/action_view_extensions/builder.rb +0 -319
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components.rb +1 -1
  13. data/lib/simple_form/components/errors.rb +1 -7
  14. data/lib/simple_form/components/hints.rb +2 -7
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/labels.rb +4 -4
  17. data/lib/simple_form/components/maxlength.rb +1 -8
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +144 -46
  20. data/lib/simple_form/form_builder.rb.orig +486 -0
  21. data/lib/simple_form/helpers.rb +1 -1
  22. data/lib/simple_form/inputs/base.rb +3 -10
  23. data/lib/simple_form/inputs/block_input.rb +1 -1
  24. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  25. data/lib/simple_form/inputs/collection_input.rb +7 -7
  26. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  27. data/lib/simple_form/inputs/password_input.rb +0 -1
  28. data/lib/simple_form/inputs/string_input.rb +0 -1
  29. data/lib/simple_form/railtie.rb +7 -0
  30. data/lib/simple_form/tags.rb +61 -0
  31. data/lib/simple_form/version.rb +1 -1
  32. data/lib/simple_form/version.rb.orig +7 -0
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form/wrappers/builder.rb +5 -29
  35. data/lib/simple_form/wrappers/many.rb +1 -1
  36. data/lib/simple_form/wrappers/root.rb +1 -1
  37. data/test/action_view_extensions/builder_test.rb +67 -87
  38. data/test/action_view_extensions/form_helper_test.rb +16 -16
  39. data/test/components/label_test.rb +46 -46
  40. data/test/form_builder/association_test.rb +23 -23
  41. data/test/form_builder/button_test.rb +4 -4
  42. data/test/form_builder/error_notification_test.rb +8 -8
  43. data/test/form_builder/error_test.rb +18 -65
  44. data/test/form_builder/general_test.rb +45 -65
  45. data/test/form_builder/hint_test.rb +23 -29
  46. data/test/form_builder/input_field_test.rb +12 -12
  47. data/test/form_builder/label_test.rb +6 -16
  48. data/test/form_builder/wrapper_test.rb +21 -21
  49. data/test/inputs/boolean_input_test.rb +23 -35
  50. data/test/inputs/collection_check_boxes_input_test.rb +55 -55
  51. data/test/inputs/collection_radio_buttons_input_test.rb +70 -79
  52. data/test/inputs/collection_select_input_test.rb +45 -51
  53. data/test/inputs/datetime_input_test.rb +11 -11
  54. data/test/inputs/disabled_test.rb +10 -10
  55. data/test/inputs/discovery_test.rb +4 -4
  56. data/test/inputs/file_input_test.rb +1 -1
  57. data/test/inputs/general_test.rb +12 -12
  58. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  59. data/test/inputs/hidden_input_test.rb +1 -1
  60. data/test/inputs/numeric_input_test.rb +3 -3
  61. data/test/inputs/priority_input_test.rb +3 -3
  62. data/test/inputs/readonly_test.rb +12 -12
  63. data/test/inputs/required_test.rb +5 -5
  64. data/test/inputs/string_input_test.rb +10 -25
  65. data/test/inputs/text_input_test.rb +1 -1
  66. data/test/support/misc_helpers.rb +24 -24
  67. data/test/support/mock_controller.rb +6 -6
  68. data/test/support/models.rb +37 -46
  69. data/test/test_helper.rb +20 -20
  70. metadata +49 -24
  71. checksums.yaml +0 -7
  72. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -1,57 +1,9 @@
1
- ## 2.1.3
2
-
3
- ### bug fix
4
- * Fix method reflection for Ruby 2.1+. [@badosu](https://github.com/badosu)
5
- * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
6
- * Use the given name in `input_html` for the hidden field in `collection_check_boxes` [@angelic](https://github.com/angelic)
7
- * Add "checkbox" class to the label of boolean input when there is no `:label`
8
- in `generate_additional_classes_for` config option [@nashby](https://github.com/nashby)
9
- * Support models with digits in their names [@webgago](https://github.com/webgago)
10
-
11
- ## 2.1.2
12
-
13
- ### bug fix
14
- * Fix XSS vulnerability on error components.
15
-
16
- ## 2.1.1
17
-
18
- ### bug fix
19
- * Fix XSS vulnerability on label, hint and error components.
20
-
21
- ## 2.1.0
1
+ ## 3.0.0.beta1
22
2
 
23
3
  ### enhancements
24
- * `input_field` supports components that don't generate tags
25
- as `:min_max`, `:maxlength`, `:placeholder`, `:pattern`, `:readonly`.
26
- Closes [#362](https://github.com/plataformatec/simple_form/issues/632).
27
- ([@nashby](https://github.com/nashby))
28
- * support for Rails eager loading.
29
- Closes [#478](https://github.com/plataformatec/simple_form/issues/478).
30
- * generate required attribute for `date_time` input.
31
- ([@nashby](https://github.com/nashby))
32
- Closes [#730](https://github.com/plataformatec/simple_form/issues/730).
33
- * `grouped_collection_select` now accepts proc/lambda as label and value method.
34
- ([@svendahlstrand](https://github.com/svendahlstrand))
35
- Closes [#623](https://github.com/plataformatec/simple_form/issues/623).
36
- * Add Zurb Foundation 3 integration.
37
- ([@balexand](https://github.com/balexand))
38
- * Generates additional wrapper class based on object + attribute name.
39
- ([@lucasmazza](https://github.com/lucasmazza))
40
- Closes [#576](https://github.com/plataformatec/simple_form/issues/576).
41
- * Allow `input_field` to work with `:defaults` options.
42
- ([@smidwap](https://github.com/smidwap))
43
-
44
- ### bug fix
45
- * Do not lookup for hints if it was explicitly given false.
46
- After #405 we added hint classes for the wrappers, but this has forced the
47
- loading of the hint text doing I18n lookups, even though it was explicitly
48
- given false. This checks for the option in `#has_hint?`, avoiding the lookup
49
- in such cases. This issues has been caught with #627, thanks to
50
- ([@shwoodard](https://github.com/shwoodard)).
51
- * Fix default I18n lookup for association input.
52
- ([@nashby](https://github.com/nashby))
53
- Closes [#679](https://github.com/plataformatec/simple_form/issues/679).
54
- * Fix escaping issue in `label_input` component
55
- ([@allomov](https://github.com/allomov))
4
+ * Support to Rails 4.
5
+ * Removed deprecated methods.
6
+ * SimpleForm no longer sets the `size` attribute automatically and the `default_input_size` setting
7
+ is now deprecated.
56
8
 
57
- Please check [v2.0](https://github.com/plataformatec/simple_form/blob/v2.0/CHANGELOG.md) for previous changes.
9
+ Please check [v2.1](https://github.com/plataformatec/simple_form/blob/v2.1/CHANGELOG.md) for previous changes.
data/README.md CHANGED
@@ -6,7 +6,11 @@ your forms. The basic goal of SimpleForm is to not touch your way of defining th
6
6
  you find the better design for your eyes. Most of the DSL was inherited from Formtastic,
7
7
  which we are thankful for and should make you feel right at home.
8
8
 
9
- INFO: This README refers to **SimpleForm** 2.1. For older releases, check the related branch for your version.
9
+ INFO: This README is [also available in a friendly navigable format](http://simple-form.plataformatec.com.br/)
10
+ and refers to **SimpleForm** 2.0. If you are using **SimpleForm** in the versions 1.x, you should
11
+ check this branch:
12
+
13
+ https://github.com/plataformatec/simple_form/tree/v1.5
10
14
 
11
15
  ## Installation
12
16
 
@@ -35,23 +39,23 @@ Also, if you want to use the country select, you will need the
35
39
  gem 'country_select'
36
40
  ```
37
41
 
38
- ### Bootstrap
42
+ ### Twitter Bootstrap
39
43
 
40
- **Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/2.3.2/) 2.3.
44
+ **SimpleForm** 2.0 can be easily integrated to the [Twitter Bootstrap](http://twitter.github.com/bootstrap).
41
45
  To do that you have to use the `bootstrap` option in the install generator, like this:
42
46
 
43
47
  ```console
44
48
  rails generate simple_form:install --bootstrap
45
49
  ```
46
50
 
47
- You have to be sure that you added a copy of the [Bootstrap](http://getbootstrap.com/2.3.2/)
51
+ You have to be sure that you added a copy of the [Twitter Bootstrap](http://twitter.github.com/bootstrap)
48
52
  assets on your application.
49
53
 
50
54
  For more information see the generator output, our
51
55
  [example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
52
56
  [the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
53
57
 
54
- **NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 up to 2.3.
58
+ **NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 or higher.
55
59
 
56
60
  ### Zurb Foundation 3
57
61
 
@@ -91,10 +95,10 @@ even a placeholder. For boolean inputs, you can add an inline label as well:
91
95
 
92
96
  ```erb
93
97
  <%= simple_form_for @user do |f| %>
94
- <%= f.input :username, :label => 'Your username please' %>
95
- <%= f.input :password, :hint => 'No special characters.' %>
96
- <%= f.input :email, :placeholder => 'user@domain.com' %>
97
- <%= f.input :remember_me, :inline_label => 'Yes, remember me' %>
98
+ <%= f.input :username, label: 'Your username please' %>
99
+ <%= f.input :password, hint: 'No special characters.' %>
100
+ <%= f.input :email, placeholder: 'user@domain.com' %>
101
+ <%= f.input :remember_me, inline_label: 'Yes, remember me' %>
98
102
  <%= f.button :submit %>
99
103
  <% end %>
100
104
  ```
@@ -104,9 +108,9 @@ of any of them:
104
108
 
105
109
  ```erb
106
110
  <%= simple_form_for @user do |f| %>
107
- <%= f.input :username, :label_html => { :class => 'my_class' } %>
108
- <%= f.input :password, :hint => false, :error_html => { :id => 'password_error'} %>
109
- <%= f.input :password_confirmation, :label => false %>
111
+ <%= f.input :username, label_html: { class: 'my_class' } %>
112
+ <%= f.input :password, hint: false, error_html: { id: 'password_error'} %>
113
+ <%= f.input :password_confirmation, label: false %>
110
114
  <%= f.button :submit %>
111
115
  <% end %>
112
116
  ```
@@ -116,9 +120,9 @@ option, for instance:
116
120
 
117
121
  ```erb
118
122
  <%= simple_form_for @user do |f| %>
119
- <%= f.input :username, :input_html => { :class => 'special' } %>
120
- <%= f.input :password, :input_html => { :maxlength => 20 } %>
121
- <%= f.input :remember_me, :input_html => { :value => '1' } %>
123
+ <%= f.input :username, input_html: { class: 'special' } %>
124
+ <%= f.input :password, input_html: { maxlength: 20 } %>
125
+ <%= f.input :remember_me, input_html: { value: '1' } %>
122
126
  <%= f.button :submit %>
123
127
  <% end %>
124
128
  ```
@@ -128,10 +132,10 @@ you can use the `:defaults` option in `simple_form_for`. Specific options in `in
128
132
  overwrite the defaults:
129
133
 
130
134
  ```erb
131
- <%= simple_form_for @user, :defaults => { :input_html => { :class => 'default_class' } } do |f| %>
132
- <%= f.input :username, :input_html => { :class => 'special' } %>
133
- <%= f.input :password, :input_html => { :maxlength => 20 } %>
134
- <%= f.input :remember_me, :input_html => { :value => '1' } %>
135
+ <%= simple_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f| %>
136
+ <%= f.input :username, input_html: { class: 'special' } %>
137
+ <%= f.input :password, input_html: { maxlength: 20 } %>
138
+ <%= f.input :remember_me, input_html: { value: '1' } %>
135
139
  <%= f.button :submit %>
136
140
  <% end %>
137
141
  ```
@@ -141,9 +145,9 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
141
145
 
142
146
  ```erb
143
147
  <%= simple_form_for @user do |f| %>
144
- <%= f.input :username, :wrapper_html => { :class => 'username' } %>
145
- <%= f.input :password, :wrapper_html => { :id => 'password' } %>
146
- <%= f.input :remember_me, :wrapper_html => { :class => 'options' } %>
148
+ <%= f.input :username, wrapper_html: { class: 'username' } %>
149
+ <%= f.input :password, wrapper_html: { id: 'password' } %>
150
+ <%= f.input :remember_me, wrapper_html: { class: 'options' } %>
147
151
  <%= f.button :submit %>
148
152
  <% end %>
149
153
  ```
@@ -156,35 +160,28 @@ And of course, the `required` property of any input can be overwritten as needed
156
160
 
157
161
  ```erb
158
162
  <%= simple_form_for @user do |f| %>
159
- <%= f.input :name, :required => false %>
163
+ <%= f.input :name, required: false %>
160
164
  <%= f.input :username %>
161
165
  <%= f.input :password %>
162
166
  <%= f.button :submit %>
163
167
  <% end %>
164
168
  ```
165
169
 
166
- By default, SimpleForm will look at the column type in the database and use an
167
- appropriate input for the column. For example, a column created with type
168
- `:text` in the database will use a `textarea` input by default. See the section
169
- [Available input types and defaults for each column
170
- type](https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type)
171
- for a complete list of defaults.
172
-
173
170
  **SimpleForm** also lets you overwrite the default input type it creates:
174
171
 
175
172
  ```erb
176
173
  <%= simple_form_for @user do |f| %>
177
174
  <%= f.input :username %>
178
175
  <%= f.input :password %>
179
- <%= f.input :description, :as => :text %>
180
- <%= f.input :accepts, :as => :radio_buttons %>
176
+ <%= f.input :description, as: :text %>
177
+ <%= f.input :accepts, as: :radio_buttons %>
181
178
  <%= f.button :submit %>
182
179
  <% end %>
183
180
  ```
184
181
 
185
182
  So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
186
- labels and a textarea instead of a text field for the description. You can also render boolean
187
- attributes using `:as => :select` to show a dropdown.
183
+ labels and a text area instead of a text field for the description. You can also render boolean
184
+ attributes using `as: :select` to show a dropdown.
188
185
 
189
186
  It is also possible to give the `:disabled` option to **SimpleForm**, and it'll automatically mark
190
187
  the wrapper as disabled with a css class, so you can style labels, hints and other components inside
@@ -192,7 +189,7 @@ the wrapper as well:
192
189
 
193
190
  ```erb
194
191
  <%= simple_form_for @user do |f| %>
195
- <%= f.input :username, :disabled => true, :hint => 'You cannot change your username.' %>
192
+ <%= f.input :username, disabled: true, hint: 'You cannot change your username.' %>
196
193
  <%= f.button :submit %>
197
194
  <% end %>
198
195
  ```
@@ -201,9 +198,9 @@ the wrapper as well:
201
198
 
202
199
  ```erb
203
200
  <%= simple_form_for @user do |f| %>
204
- <%= f.input :date_of_birth, :as => :date, :start_year => Date.today.year - 90,
205
- :end_year => Date.today.year - 12, :discard_day => true,
206
- :order => [:month, :year] %>
201
+ <%= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
202
+ end_year: Date.today.year - 12, discard_day: true,
203
+ order: [:month, :year] %>
207
204
  <%= f.button :submit %>
208
205
  <% end %>
209
206
  ```
@@ -216,7 +213,7 @@ the wrapper as well:
216
213
  <%= f.label :username %>
217
214
  <%= f.input_field :username %>
218
215
  <%= f.hint 'No special characters, please!' %>
219
- <%= f.error :username, :id => 'user_name_error' %>
216
+ <%= f.error :username, id: 'user_name_error' %>
220
217
  <%= f.full_error :token %>
221
218
  <%= f.submit 'Save' %>
222
219
  <% end %>
@@ -224,6 +221,28 @@ the wrapper as well:
224
221
 
225
222
  Any extra option passed to these methods will be rendered as html option.
226
223
 
224
+ ### Stripping away all wrapper divs
225
+
226
+ **SimpleForm** also allows you to strip away all the div wrappers around the `<input>` field that is generated with the usual `f.input`.
227
+ The easiest way to achieve this is to use `f.input_field`.
228
+
229
+ Example:
230
+
231
+ ```erb
232
+ simple_form_for @user do |f|
233
+ f.input_field :name
234
+ end
235
+ ```
236
+
237
+ Produces:
238
+
239
+ ```erb
240
+ <input class="string required" id="user_name" maxlength="100"
241
+ name="user[name]" size="100" type="text" value="Carlos" />
242
+ ```
243
+
244
+ To view the actual RDocs for this, check them out here - http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:input_field
245
+
227
246
  ### Collections
228
247
 
229
248
  And what if you want to create a select containing the age from 18 to 60 in your form? You can do it
@@ -232,13 +251,13 @@ overriding the `:collection` option:
232
251
  ```erb
233
252
  <%= simple_form_for @user do |f| %>
234
253
  <%= f.input :user %>
235
- <%= f.input :age, :collection => 18..60 %>
254
+ <%= f.input :age, collection: 18..60 %>
236
255
  <%= f.button :submit %>
237
256
  <% end %>
238
257
  ```
239
258
 
240
259
  Collections can be arrays or ranges, and when a `:collection` is given the `:select` input will be
241
- rendered by default, so we don't need to pass the `:as => :select` option. Other types of collection
260
+ rendered by default, so we don't need to pass the `as: :select` option. Other types of collection
242
261
  are `:radio_buttons` and `:check_boxes`. Those are added by **SimpleForm** to Rails set of form
243
262
  helpers (read Extra Helpers session below for more information).
244
263
 
@@ -255,13 +274,13 @@ translation. All other options given are sent straight to the underlying helper.
255
274
  can give prompt as:
256
275
 
257
276
  ```ruby
258
- f.input :age, :collection => 18..60, :prompt => "Select your age"
277
+ f.input :age, collection: 18..60, prompt: "Select your age"
259
278
  ```
260
279
 
261
280
  It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
262
281
 
263
282
  ```ruby
264
- f.input :country_id, :collection => @continents, :as => :grouped_select, :group_method => :countries
283
+ f.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries
265
284
  ```
266
285
 
267
286
  Grouped collection inputs accept the same `:label_method` and `:value_method` options, which will be
@@ -280,8 +299,8 @@ used to retrieve label/value attributes for the `option` tags. Besides that, you
280
299
  `:priority` as option to select which time zones and/or countries should be given higher priority:
281
300
 
282
301
  ```ruby
283
- f.input :residence_country, :priority => [ "Brazil" ]
284
- f.input :time_zone, :priority => /US/
302
+ f.input :residence_country, priority: [ "Brazil" ]
303
+ f.input :time_zone, priority: /US/
285
304
  ```
286
305
 
287
306
  Those values can also be configured with a default value to be used site use through the
@@ -291,12 +310,12 @@ Note: While using `country_select` if you want to restrict to only a subset of c
291
310
  drop down then you may use the `:collection` option:
292
311
 
293
312
  ```ruby
294
- f.input :shipping_country, :priority => [ "Brazil" ], :collection => [ "Australia", "Brazil", "New Zealand"]
313
+ f.input :shipping_country, priority: [ "Brazil" ], collection: [ "Australia", "Brazil", "New Zealand"]
295
314
  ```
296
315
 
297
316
  ### Associations
298
317
 
299
- To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or checkboxes.
318
+ To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or check boxes.
300
319
  Lets see how it works: imagine you have a user model that belongs to a company and has_and_belongs_to_many
301
320
  roles. The structure would be something like:
302
321
 
@@ -328,11 +347,11 @@ Now we have the user form:
328
347
 
329
348
  Simple enough, right? This is going to render a `:select` input for choosing the `:company`, and another
330
349
  `:select` input with `:multiple` option for the `:roles`. You can, of course, change it to use radio
331
- buttons and checkboxes as well:
350
+ buttons and check boxes as well:
332
351
 
333
352
  ```ruby
334
- f.association :company, :as => :radio_buttons
335
- f.association :roles, :as => :check_boxes
353
+ f.association :company, as: :radio_buttons
354
+ f.association :roles, as: :check_boxes
336
355
  ```
337
356
 
338
357
  The association helper just invokes `input` under the hood, so all options available to `:select`,
@@ -340,13 +359,13 @@ The association helper just invokes `input` under the hood, so all options avail
340
359
  the collection by hand, all together with the prompt:
341
360
 
342
361
  ```ruby
343
- f.association :company, :collection => Company.active.all(:order => 'name'), :prompt => "Choose a Company"
362
+ f.association :company, collection: Company.active.all(order: 'name'), prompt: "Choose a Company"
344
363
  ```
345
364
 
346
365
  In case you want to declare different labels and values:
347
366
 
348
367
  ```ruby
349
- f.association :company, :label_method => :company_name, :value_method => :id, :include_blank => false
368
+ f.association :company, label_method: :company_name, value_method: :id, include_blank: false
350
369
  ```
351
370
 
352
371
  ### Buttons
@@ -369,7 +388,7 @@ calling input with a block like so:
369
388
 
370
389
  ```erb
371
390
  <%= f.input :role do %>
372
- <%= f.select :role, Role.all.map { |r| [r.name, r.id, { :class => r.company.id }] }, :include_blank => true %>
391
+ <%= f.select :role, Role.all.map { |r| [r.name, r.id, { class: r.company.id }] }, include_blank: true %>
373
392
  <% end %>
374
393
  ```
375
394
 
@@ -415,7 +434,7 @@ end
415
434
 
416
435
  #### Collection Check Boxes
417
436
 
418
- Creates a collection of checkboxes with labels associated (same API as `collection_select`):
437
+ Creates a collection of check boxes with labels associated (same API as `collection_select`):
419
438
 
420
439
  ```ruby
421
440
  form_for @user do |f|
@@ -440,36 +459,36 @@ form_for @user do |f|
440
459
  end
441
460
  ```
442
461
 
443
- ## Available input types and defaults for each column type
444
-
445
- The following table shows the html element you will get for each attribute
446
- according to its database definition. These defaults can be changed by
447
- specifying the helper method in the column `Mapping` as the `as:` option.
448
-
449
- Mapping | Generated HTML Element | Database Column Type
450
- --------------- |:-------------------------------------|:--------------------
451
- `boolean` | `input[type=checkbox]` | `boolean`
452
- `string` | `input[type=text]` | `string`
453
- `email` | `input[type=email]` | `string` with `name =~ /email/`
454
- `url` | `input[type=url]` | `string` with `name =~ /url/`
455
- `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
456
- `password` | `input[type=password]` | `string` with `name =~ /password/`
457
- `search` | `input[type=search]` | -
458
- `text` | `textarea` | `text`
459
- `file` | `input[type=file]` | `string` responding to file methods
460
- `hidden` | `input[type=hidden]` | -
461
- `integer` | `input[type=number]` | `integer`
462
- `float` | `input[type=number]` | `float`
463
- `decimal` | `input[type=number]` | `decimal`
464
- `range` | `input[type=range]` | -
465
- `datetime` | `select` | `datetime/timestamp`
466
- `date` | `select` | `date`
467
- `time` | `select` | `time`
468
- `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
469
- `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
470
- `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
471
- `country` | `select` (countries as options) | `string` with `name =~ /country/`
472
- `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
462
+ ## Mappings/Inputs available
463
+
464
+ **SimpleForm** comes with a lot of default mappings:
465
+
466
+ ```text
467
+ Mapping Input Column Type
468
+
469
+ boolean check box boolean
470
+ string text field string
471
+ email email field string with name matching "email"
472
+ url url field string with name matching "url"
473
+ tel tel field string with name matching "phone"
474
+ password password field string with name matching "password"
475
+ search search -
476
+ text text area text
477
+ file file field string, responding to file methods
478
+ hidden hidden field -
479
+ integer number field integer
480
+ float number field float
481
+ decimal number field decimal
482
+ range range field -
483
+ datetime datetime select datetime/timestamp
484
+ date date select date
485
+ time time select time
486
+ select collection select belongs_to/has_many/has_and_belongs_to_many associations
487
+ radio_buttons collection radio buttons belongs_to
488
+ check_boxes collection check boxes has_many/has_and_belongs_to_many associations
489
+ country country select string with name matching "country"
490
+ time_zone time zone select string with name matching "time_zone"
491
+ ```
473
492
 
474
493
  ## Custom inputs
475
494
 
@@ -488,9 +507,8 @@ end
488
507
  And use it in your views:
489
508
 
490
509
  ```ruby
491
- f.input :money, :as => :currency
510
+ f.input :money, as: :currency
492
511
  ```
493
- Note, you may have to create the `app/inputs/` directory and restart your webserver.
494
512
 
495
513
  You can also redefine existing **SimpleForm** inputs by creating a new class with the same name. For
496
514
  instance, if you want to wrap date/time/datetime in a div, you can do:
@@ -524,7 +542,7 @@ Create a helper method that calls `simple_form_for` with a custom builder:
524
542
  ```ruby
525
543
  def custom_form_for(object, *args, &block)
526
544
  options = args.extract_options!
527
- simple_form_for(object, *(args << options.merge(:builder => CustomFormBuilder)), &block)
545
+ simple_form_for(object, *(args << options.merge(builder: CustomFormBuilder)), &block)
528
546
  end
529
547
  ```
530
548
 
@@ -533,7 +551,7 @@ Create a form builder class that inherits from `SimpleForm::FormBuilder`.
533
551
  ```ruby
534
552
  class CustomFormBuilder < SimpleForm::FormBuilder
535
553
  def input(attribute_name, options = {}, &block)
536
- options[:input_html].merge! :class => 'custom'
554
+ options[:input_html].merge! class: 'custom'
537
555
  super
538
556
  end
539
557
  end
@@ -616,7 +634,7 @@ that would post either `male` or `female` as value. With **SimpleForm** you coul
616
634
  like this:
617
635
 
618
636
  ```ruby
619
- f.input :gender, :collection => [:male, :female]
637
+ f.input :gender, collection: [:male, :female]
620
638
  ```
621
639
 
622
640
  And **SimpleForm** will try a lookup like this in your locale file, to find the right labels to show:
@@ -678,7 +696,7 @@ en:
678
696
  This difference exists because **SimpleForm** relies on `object_name` provided by Rails'
679
697
  FormBuilder to determine the translation path for a given object instead of `i18n_key` from the
680
698
  object itself. Thus, similarly, if a form for an `Admin::User` object is defined by calling
681
- `simple_form_for @admin_user, :as => :some_user`, **SimpleForm** will look for translations
699
+ `simple_form_for @admin_user, as: :some_user`, **SimpleForm** will look for translations
682
700
  under `some_user` instead of `admin_user`.
683
701
 
684
702
  ## Configuration
@@ -694,8 +712,8 @@ With **SimpleForm** you can configure how your components will be rendered using
694
712
  The syntax looks like this:
695
713
 
696
714
  ```ruby
697
- config.wrappers :tag => :div, :class => :input,
698
- :error_class => :field_with_errors do |b|
715
+ config.wrappers tag: :div, class: :input,
716
+ error_class: :field_with_errors do |b|
699
717
 
700
718
  # Form extensions
701
719
  b.use :html5
@@ -706,8 +724,8 @@ config.wrappers :tag => :div, :class => :input,
706
724
 
707
725
  # Form components
708
726
  b.use :label_input
709
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
710
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
727
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
728
+ b.use :error, wrap_with: { tag: :span, class: :error }
711
729
  end
712
730
  ```
713
731
 
@@ -730,9 +748,9 @@ You can create new _Form components_ using the wrappers API as in the following
730
748
  config.wrappers do |b|
731
749
  b.use :placeholder
732
750
  b.use :label_input
733
- b.wrapper :tag => :div, :class => 'separator' do |component|
734
- component.use :hint, :wrap_with => { :tag => :span, :class => :hint }
735
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
751
+ b.wrapper tag: :div, class: 'separator' do |component|
752
+ component.use :hint, wrap_with: { tag: :span, class: :hint }
753
+ component.use :error, wrap_with: { tag: :span, class: :error }
736
754
  end
737
755
  end
738
756
  ```
@@ -745,9 +763,9 @@ If you want to customize the custom _Form components_ on demand you can give it
745
763
  config.wrappers do |b|
746
764
  b.use :placeholder
747
765
  b.use :label_input
748
- b.wrapper :my_wrapper, :tag => :div, :class => 'separator' do |component|
749
- component.use :hint, :wrap_with => { :tag => :span, :class => :hint }
750
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
766
+ b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
767
+ component.use :hint, wrap_with: { tag: :span, class: :hint }
768
+ component.use :error, wrap_with: { tag: :span, class: :error }
751
769
  end
752
770
  end
753
771
  ```
@@ -756,13 +774,13 @@ and now you can pass options to your `input` calls to customize the `:my_wrapper
756
774
 
757
775
  ```ruby
758
776
  # Completely turns off the custom wrapper
759
- f.input :name, :my_wrapper => false
777
+ f.input :name, my_wrapper: false
760
778
 
761
779
  # Configure the html
762
- f.input :name, :my_wrapper_html => { :id => 'special_id' }
780
+ f.input :name, my_wrapper_html: { id: 'special_id' }
763
781
 
764
782
  # Configure the tag
765
- f.input :name, :my_wrapper_tag => :p
783
+ f.input :name, my_wrapper_tag: :p
766
784
  ```
767
785
 
768
786
  You can also define more than one wrapper and pick one to render in a specific form or input.
@@ -779,13 +797,13 @@ and use it in this way:
779
797
 
780
798
  ```ruby
781
799
  # Specifying to whole form
782
- simple_form_for @user, :wrapper => :small do |f|
800
+ simple_form_for @user, wrapper: :small do |f|
783
801
  f.input :name
784
802
  end
785
803
 
786
804
  # Specifying to one input
787
805
  simple_form_for @user do |f|
788
- f.input :name, :wrapper => :small
806
+ f.input :name, wrapper: :small
789
807
  end
790
808
  ```
791
809
 
@@ -794,17 +812,17 @@ hints or placeholders, but you don't want them to be generated automatically. Yo
794
812
  default values to `false` or use the `optional` method. Is preferible to use the `optional` syntax:
795
813
 
796
814
  ```ruby
797
- config.wrappers :placeholder => false do |b|
815
+ config.wrappers placeholder: false do |b|
798
816
  b.use :placeholder
799
817
  b.use :label_input
800
- b.wrapper :tag => :div, :class => 'separator' do |component|
801
- component.optional :hint, :wrap_with => { :tag => :span, :class => :hint }
802
- component.use :error, :wrap_with => { :tag => :span, :class => :error }
818
+ b.wrapper tag: :div, class: 'separator' do |component|
819
+ component.optional :hint, wrap_with: { tag: :span, class: :hint }
820
+ component.use :error, wrap_with: { tag: :span, class: :error }
803
821
  end
804
822
  end
805
823
  ```
806
824
 
807
- By setting it as `optional`, a hint will only be generated when `:hint => true` is explicitly used.
825
+ By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
808
826
  The same for placehold.
809
827
 
810
828
  ## HTML 5 Notice
@@ -839,7 +857,7 @@ help you to use some generic javascript validation.
839
857
  You can also add `novalidate` to a specific form by setting the option on the form itself:
840
858
 
841
859
  ```erb
842
- <%= simple_form_for(resource, :html => {:novalidate => true}) do |form| %>
860
+ <%= simple_form_for(resource, html: {novalidate: true}) do |form| %>
843
861
  ```
844
862
 
845
863
  Please notice that any of the configurations above will disable the `placeholder` component,