simple_form 3.5.0 → 3.5.1

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +38 -28
  4. data/lib/generators/simple_form/install_generator.rb +1 -0
  5. data/lib/generators/simple_form/templates/_form.html.erb +1 -0
  6. data/lib/generators/simple_form/templates/_form.html.haml +1 -0
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -0
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +1 -0
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +2 -1
  10. data/lib/simple_form.rb +8 -6
  11. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  12. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
  13. data/lib/simple_form/components.rb +1 -0
  14. data/lib/simple_form/components/errors.rb +2 -1
  15. data/lib/simple_form/components/hints.rb +1 -0
  16. data/lib/simple_form/components/html5.rb +1 -0
  17. data/lib/simple_form/components/label_input.rb +2 -1
  18. data/lib/simple_form/components/labels.rb +2 -1
  19. data/lib/simple_form/components/maxlength.rb +1 -0
  20. data/lib/simple_form/components/min_max.rb +1 -0
  21. data/lib/simple_form/components/minlength.rb +2 -1
  22. data/lib/simple_form/components/pattern.rb +1 -0
  23. data/lib/simple_form/components/placeholders.rb +1 -0
  24. data/lib/simple_form/components/readonly.rb +1 -0
  25. data/lib/simple_form/error_notification.rb +1 -0
  26. data/lib/simple_form/form_builder.rb +9 -3
  27. data/lib/simple_form/helpers.rb +1 -0
  28. data/lib/simple_form/helpers/autofocus.rb +1 -0
  29. data/lib/simple_form/helpers/disabled.rb +1 -0
  30. data/lib/simple_form/helpers/readonly.rb +1 -0
  31. data/lib/simple_form/helpers/required.rb +1 -0
  32. data/lib/simple_form/helpers/validators.rb +2 -1
  33. data/lib/simple_form/i18n_cache.rb +1 -0
  34. data/lib/simple_form/inputs.rb +1 -0
  35. data/lib/simple_form/inputs/base.rb +2 -1
  36. data/lib/simple_form/inputs/block_input.rb +1 -0
  37. data/lib/simple_form/inputs/boolean_input.rb +3 -2
  38. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  39. data/lib/simple_form/inputs/collection_input.rb +3 -2
  40. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_select_input.rb +1 -0
  42. data/lib/simple_form/inputs/date_time_input.rb +1 -0
  43. data/lib/simple_form/inputs/file_input.rb +1 -0
  44. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
  45. data/lib/simple_form/inputs/hidden_input.rb +1 -0
  46. data/lib/simple_form/inputs/numeric_input.rb +1 -0
  47. data/lib/simple_form/inputs/password_input.rb +1 -0
  48. data/lib/simple_form/inputs/priority_input.rb +1 -0
  49. data/lib/simple_form/inputs/range_input.rb +1 -0
  50. data/lib/simple_form/inputs/string_input.rb +1 -0
  51. data/lib/simple_form/inputs/text_input.rb +1 -0
  52. data/lib/simple_form/map_type.rb +1 -0
  53. data/lib/simple_form/railtie.rb +1 -0
  54. data/lib/simple_form/tags.rb +1 -0
  55. data/lib/simple_form/version.rb +2 -1
  56. data/lib/simple_form/wrappers.rb +1 -0
  57. data/lib/simple_form/wrappers/builder.rb +1 -0
  58. data/lib/simple_form/wrappers/leaf.rb +2 -1
  59. data/lib/simple_form/wrappers/many.rb +1 -0
  60. data/lib/simple_form/wrappers/root.rb +1 -0
  61. data/lib/simple_form/wrappers/single.rb +2 -1
  62. data/test/action_view_extensions/builder_test.rb +6 -5
  63. data/test/action_view_extensions/form_helper_test.rb +3 -2
  64. data/test/components/label_test.rb +5 -4
  65. data/test/form_builder/association_test.rb +27 -2
  66. data/test/form_builder/button_test.rb +1 -0
  67. data/test/form_builder/error_notification_test.rb +1 -0
  68. data/test/form_builder/error_test.rb +6 -0
  69. data/test/form_builder/general_test.rb +10 -3
  70. data/test/form_builder/hint_test.rb +6 -0
  71. data/test/form_builder/input_field_test.rb +2 -1
  72. data/test/form_builder/label_test.rb +9 -3
  73. data/test/form_builder/wrapper_test.rb +3 -2
  74. data/test/generators/simple_form_generator_test.rb +4 -3
  75. data/test/inputs/boolean_input_test.rb +9 -0
  76. data/test/inputs/collection_check_boxes_input_test.rb +30 -14
  77. data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
  78. data/test/inputs/collection_select_input_test.rb +40 -39
  79. data/test/inputs/datetime_input_test.rb +5 -4
  80. data/test/inputs/disabled_test.rb +1 -0
  81. data/test/inputs/discovery_test.rb +1 -0
  82. data/test/inputs/file_input_test.rb +1 -0
  83. data/test/inputs/general_test.rb +3 -2
  84. data/test/inputs/grouped_collection_select_input_test.rb +11 -10
  85. data/test/inputs/hidden_input_test.rb +1 -0
  86. data/test/inputs/numeric_input_test.rb +2 -1
  87. data/test/inputs/priority_input_test.rb +1 -0
  88. data/test/inputs/readonly_test.rb +1 -0
  89. data/test/inputs/required_test.rb +1 -0
  90. data/test/inputs/string_input_test.rb +2 -1
  91. data/test/inputs/text_input_test.rb +1 -0
  92. data/test/simple_form_test.rb +1 -0
  93. data/test/support/discovery_inputs.rb +1 -0
  94. data/test/support/misc_helpers.rb +2 -1
  95. data/test/support/mock_controller.rb +4 -0
  96. data/test/support/models.rb +36 -12
  97. data/test/test_helper.rb +2 -0
  98. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21876f0dc22464c3d3cc192c6cb1b387d87a3ffa
4
- data.tar.gz: 5dca755be1ecf07cf96360b81c338333787976fb
3
+ metadata.gz: 26d8e98f7207ee39c87221a646468a32291c982b
4
+ data.tar.gz: c3706e88eef3b4804381d8dbafd343819dbea517
5
5
  SHA512:
6
- metadata.gz: fdda2693ca2da6c6b33e393b960969c46de2a1fbea4475cb412429020bb029c4ce1e6fb210e7bfeb6f7e5d19630b9b68f6f89f29eaf02cb200ecf36d22d3ff60
7
- data.tar.gz: 912d804b0b3d7b832b7ddc1a1f3e1a57a88fe5ed2d9907d472bd12a3882e1b1b2442e0eae2a95dd9abaa1fa2f4cd74832f6f80ed17144162d6b528ce7d5856ee
6
+ metadata.gz: ee943633a1817a276e27b2aa55a9767169bf75791e17d0fe236f10c057f9442187ca0f6914da62e070a5418ec06c9d31dd61c2f662ee4c99fe52cec02ec1edd0
7
+ data.tar.gz: f5019c5c6b057a008d5c1403d030798f3bdf2393b42410afa1cdc3e8feecd4c79e4a721a3a1fd976f147460ca497a199f9092834d4d26fb32d76c1cadbab2454
@@ -1,5 +1,22 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 3.5.1
4
+
5
+ ### Enhancements
6
+ * Exclude hidden field when unchecked_value: false. [@fschwahn](https://github.com/fschwahn)
7
+ * Add frozen_string_literal magic comment to several files. [@oniofchaos](https://github.com/oniofchaos)
8
+ * Try convert @object to model in case we got decorated object [@timurvafin](https://github.com/timurvafin)
9
+ * Code cleanup [@Fornacula](https://github.com/Fornacula)
10
+
11
+ ### Bug fix
12
+ * Fix error when the scope from association has parameter. [@feliperenan](https://github.com/feliperenan)
13
+ * Only call `where` on associations when they respond to it. [@anicholson](https://github.com/anicholson)
14
+ * require 'action_pack' before using it. [@etagwerker](https://github.com/etagwerker)
15
+ * Check if Rails.env is defined. [@etagwerker](https://github.com/etagwerker)
16
+ * Fix minlength. [@mameier](https://github.com/mameier)
17
+ * Make errors_on_attribute return [] when not present. [@redrick](https://github.com/redrick)
18
+ * Fix boolean inputs in nested style for label non-string. [@feliperenan](https://github.com/feliperenan)
19
+
3
20
  ## 3.5.0
4
21
 
5
22
  * Updated gem dependency to support Rails 5.1.x.
data/README.md CHANGED
@@ -325,8 +325,18 @@ Collection inputs accept two other options beside collections:
325
325
  Those methods are useful to manipulate the given collection. Both of these options also accept
326
326
  lambda/procs in case you want to calculate the value or label in a special way eg. custom
327
327
  translation. You can also define a `to_label` method on your model as **Simple Form** will search for
328
- and use `:to_label` as a `:label_method` first if it is found. All other options given are sent
329
- straight to the underlying helper. For example, you can give prompt as:
328
+ and use `:to_label` as a `:label_method` first if it is found.
329
+
330
+ By default, **Simple Form** will use the first item from an array as the label and the second one as the value.
331
+ If you want to change this behavior you must make it explicit, like this:
332
+
333
+ ```erb
334
+ <%= simple_form_for @user do |f| %>
335
+ <%= f.input :gender, as: :radio_buttons, collection: [['0', 'female'], ['1', 'male']], label_method: :second, value_method: :first %>
336
+ <% end %>
337
+ ```
338
+
339
+ All other options given are sent straight to the underlying helper. For example, you can give prompt as:
330
340
 
331
341
  ```ruby
332
342
  f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
@@ -541,31 +551,31 @@ The following table shows the html element you will get for each attribute
541
551
  according to its database definition. These defaults can be changed by
542
552
  specifying the helper method in the column `Mapping` as the `as:` option.
543
553
 
544
- Mapping | Generated HTML Element | Database Column Type
545
- --------------- |:-------------------------------------|:--------------------
546
- `boolean` | `input[type=checkbox]` | `boolean`
547
- `string` | `input[type=text]` | `string`
548
- `email` | `input[type=email]` | `string` with `name =~ /email/`
549
- `url` | `input[type=url]` | `string` with `name =~ /url/`
550
- `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
551
- `password` | `input[type=password]` | `string` with `name =~ /password/`
552
- `search` | `input[type=search]` | -
553
- `uuid` | `input[type=text]` | `uuid`
554
- `text` | `textarea` | `text`
555
- `file` | `input[type=file]` | `string` responding to file methods
556
- `hidden` | `input[type=hidden]` | -
557
- `integer` | `input[type=number]` | `integer`
558
- `float` | `input[type=number]` | `float`
559
- `decimal` | `input[type=number]` | `decimal`
560
- `range` | `input[type=range]` | -
561
- `datetime` | `datetime select` | `datetime/timestamp`
562
- `date` | `date select` | `date`
563
- `time` | `time select` | `time`
564
- `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
565
- `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
566
- `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
567
- `country` | `select` (countries as options) | `string` with `name =~ /country/`
568
- `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
554
+ Mapping | Generated HTML Element | Database Column Type
555
+ --------------- |--------------------------------------|---------------------
556
+ `boolean` | `input[type=checkbox]` | `boolean`
557
+ `string` | `input[type=text]` | `string`
558
+ `email` | `input[type=email]` | `string` with `name =~ /email/`
559
+ `url` | `input[type=url]` | `string` with `name =~ /url/`
560
+ `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
561
+ `password` | `input[type=password]` | `string` with `name =~ /password/`
562
+ `search` | `input[type=search]` | -
563
+ `uuid` | `input[type=text]` | `uuid`
564
+ `text` | `textarea` | `text`
565
+ `file` | `input[type=file]` | `string` responding to file methods
566
+ `hidden` | `input[type=hidden]` | -
567
+ `integer` | `input[type=number]` | `integer`
568
+ `float` | `input[type=number]` | `float`
569
+ `decimal` | `input[type=number]` | `decimal`
570
+ `range` | `input[type=range]` | -
571
+ `datetime` | `datetime select` | `datetime/timestamp`
572
+ `date` | `date select` | `date`
573
+ `time` | `time select` | `time`
574
+ `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
575
+ `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
576
+ `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
577
+ `country` | `select` (countries as options) | `string` with `name =~ /country/`
578
+ `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
569
579
 
570
580
  ## Custom inputs
571
581
 
@@ -1076,7 +1086,7 @@ https://github.com/plataformatec/simple_form/issues
1076
1086
 
1077
1087
  ## License
1078
1088
 
1079
- MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
1089
+ MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
1080
1090
 
1081
1091
  You are not granted rights or licenses to the trademarks of the Plataformatec, including without
1082
1092
  limitation the Simple Form name or logo.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Generators
3
4
  class InstallGenerator < Rails::Generators::Base
@@ -1,3 +1,4 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
3
  <%%= f.error_notification %>
3
4
 
@@ -1,3 +1,4 @@
1
+ -# frozen_string_literal: true
1
2
  = simple_form_for(@<%= singular_table_name %>) do |f|
2
3
  = f.error_notification
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Use this setup block to configure all options available in SimpleForm.
2
3
  SimpleForm.setup do |config|
3
4
  # Wrappers are used by the form builder to generate a
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Use this setup block to configure all options available in SimpleForm.
2
3
  SimpleForm.setup do |config|
3
4
  config.error_notification_class = 'alert alert-danger'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Use this setup block to configure all options available in SimpleForm.
2
3
  SimpleForm.setup do |config|
3
4
  # Don't forget to edit this file to adapt it to your needs (specially
@@ -46,7 +47,7 @@ SimpleForm.setup do |config|
46
47
  b.optional :readonly
47
48
 
48
49
  b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
49
- ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
50
+ ba.wrapper tag: 'label', class: 'checkbox' do |bb|
50
51
  bb.use :input
51
52
  bb.use :label_text
52
53
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  require 'action_view'
3
+ require 'action_pack'
2
4
  require 'simple_form/action_view_extensions/form_helper'
3
5
  require 'simple_form/action_view_extensions/builder'
4
6
  require 'active_support/core_ext/hash/slice'
@@ -58,11 +60,11 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
58
60
 
59
61
  # Series of attemps to detect a default label method for collection.
60
62
  mattr_accessor :collection_label_methods
61
- @@collection_label_methods = [:to_label, :name, :title, :to_s]
63
+ @@collection_label_methods = %i[to_label name title to_s]
62
64
 
63
65
  # Series of attemps to detect a default value method for collection.
64
66
  mattr_accessor :collection_value_methods
65
- @@collection_value_methods = [:id, :to_s]
67
+ @@collection_value_methods = %i[id to_s]
66
68
 
67
69
  # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
68
70
  mattr_accessor :collection_wrapper_tag
@@ -84,7 +86,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
84
86
 
85
87
  # How the label text should be generated altogether with the required text.
86
88
  mattr_accessor :label_text
87
- @@label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
89
+ @@label_text = ->(label, required, explicit_label) { "#{required} #{label}" }
88
90
 
89
91
  # You can define the class to be used on all labels. Defaults to none.
90
92
  mattr_accessor :label_class
@@ -108,7 +110,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
108
110
 
109
111
  # You can define which elements should obtain additional classes.
110
112
  mattr_accessor :generate_additional_classes_for
111
- @@generate_additional_classes_for = [:wrapper, :label, :input]
113
+ @@generate_additional_classes_for = %i[wrapper label input]
112
114
 
113
115
  # Whether attributes are required by default or not.
114
116
  mattr_accessor :required_by_default
@@ -120,7 +122,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
120
122
 
121
123
  # Collection of methods to detect if a file type was given.
122
124
  mattr_accessor :file_methods
123
- @@file_methods = [:mounted_as, :file?, :public_filename]
125
+ @@file_methods = %i[mounted_as file? public_filename]
124
126
 
125
127
  # Custom mappings for input types. This should be a hash containing a regexp
126
128
  # to match as key, and the input type that will be used when the field name
@@ -163,7 +165,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
163
165
 
164
166
  # Cache SimpleForm inputs discovery.
165
167
  mattr_accessor :cache_discovery
166
- @@cache_discovery = defined?(Rails) && !Rails.env.development?
168
+ @@cache_discovery = defined?(Rails.env) && !Rails.env.development?
167
169
 
168
170
  # Adds a class to each generated button, mostly for compatiblity.
169
171
  mattr_accessor :button_class
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module ActionViewExtensions
3
4
  # A collection of methods required by simple_form but added to rails default form.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module ActionViewExtensions
3
4
  # This module creates SimpleForm wrappers around default form_for and fields_for.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  # Components are a special type of helpers that can work on their own.
3
4
  # For example, by using a component, it will automatically change the
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  module Errors
@@ -38,7 +39,7 @@ module SimpleForm
38
39
  end
39
40
 
40
41
  def errors_on_attribute
41
- object.errors[attribute_name]
42
+ object.errors[attribute_name] || []
42
43
  end
43
44
 
44
45
  def full_errors_on_attribute
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  module HTML5
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  module LabelInput
@@ -20,7 +21,7 @@ module SimpleForm
20
21
  def deprecated_component(namespace, wrapper_options)
21
22
  method = method(namespace)
22
23
 
23
- if method.arity == 0
24
+ if method.arity.zero?
24
25
  ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: namespace })
25
26
 
26
27
  method.call
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  module Labels
@@ -7,7 +8,7 @@ module SimpleForm
7
8
  def translate_required_html
8
9
  i18n_cache :translate_required_html do
9
10
  I18n.t(:"simple_form.required.html", default:
10
- %[<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>]
11
+ %(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
11
12
  )
12
13
  end
13
14
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  module MinMax
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
4
5
  module Minlength
5
6
  def minlength(wrapper_options = nil)
6
- input_html_options[:minlength] ||= minimum_length_from_validation || limit
7
+ input_html_options[:minlength] ||= minimum_length_from_validation
7
8
  nil
8
9
  end
9
10
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Components
3
4
  # Needs to be enabled in order to do automatic lookups.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  class ErrorNotification
3
4
  delegate :object, :object_name, :template, to: :@builder
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_support/core_ext/object/deep_dup'
2
3
  require 'simple_form/map_type'
3
4
  require 'simple_form/tags'
@@ -12,7 +13,7 @@ module SimpleForm
12
13
  'update' => 'edit'
13
14
  }
14
15
 
15
- ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :minlength, :placeholder, :pattern, :readonly]
16
+ ATTRIBUTE_COMPONENTS = %i[html5 min_max maxlength minlength placeholder pattern readonly]
16
17
 
17
18
  extend MapType
18
19
  include SimpleForm::Inputs
@@ -38,6 +39,7 @@ module SimpleForm
38
39
 
39
40
  def initialize(*) #:nodoc:
40
41
  super
42
+ @object = convert_to_model(@object)
41
43
  @defaults = options[:defaults]
42
44
  @wrapper = SimpleForm.wrapper(options[:wrapper] || SimpleForm.default_wrapper)
43
45
  end
@@ -461,13 +463,17 @@ module SimpleForm
461
463
  relation = reflection.klass.all
462
464
 
463
465
  if reflection.respond_to?(:scope) && reflection.scope
464
- relation = reflection.klass.instance_exec(&reflection.scope)
466
+ if reflection.scope.parameters.any?
467
+ relation = reflection.klass.instance_exec(object, &reflection.scope)
468
+ else
469
+ relation = reflection.klass.instance_exec(&reflection.scope)
470
+ end
465
471
  else
466
472
  order = reflection.options[:order]
467
473
  conditions = reflection.options[:conditions]
468
474
  conditions = object.instance_exec(&conditions) if conditions.respond_to?(:call)
469
475
 
470
- relation = relation.where(conditions)
476
+ relation = relation.where(conditions) if relation.respond_to?(:where)
471
477
  relation = relation.order(order) if relation.respond_to?(:order)
472
478
  end
473
479
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  # Helpers are made of several helpers that cannot be turned on automatically.
3
4
  # For instance, disabled cannot be turned on automatically, it requires the
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Helpers
3
4
  module Autofocus
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Helpers
3
4
  module Disabled
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Helpers
3
4
  module Readonly
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Helpers
3
4
  module Required
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Helpers
3
4
  module Validators
@@ -24,7 +25,7 @@ module SimpleForm
24
25
  end
25
26
 
26
27
  def action_validator_match?(validator)
27
- return true if !validator.options.include?(:on)
28
+ return true unless validator.options.include?(:on)
28
29
 
29
30
  case validator.options[:on]
30
31
  when :save
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  # A lot of configuration values are retrived from I18n,
3
4
  # like boolean collection, required string. This module provides
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Inputs
3
4
  extend ActiveSupport::Autoload
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'simple_form/i18n_cache'
2
3
  require 'active_support/core_ext/string/output_safety'
3
4
  require 'action_view/helpers'
@@ -95,7 +96,7 @@ module SimpleForm
95
96
  end
96
97
 
97
98
  def input_class
98
- "#{lookup_model_names.join("_")}_#{reflection_or_attribute_name}"
99
+ "#{lookup_model_names.join('_')}_#{reflection_or_attribute_name}"
99
100
  end
100
101
 
101
102
  private