pantographe / view_component-form

Rails FormBuilder for ViewComponent
MIT License
206 stars 16 forks source link

`time_zone_select` helper does not pass options correctly #83

Closed boardfish closed 2 years ago

boardfish commented 2 years ago

Using the following within a form_with with a model:

<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.all %>

I'm getting the following error:

web       | ActionView::Template::Error (undefined method `merge' for #<Array:0x0000559a41f11a18>):
web       |     28: 
web       |     29:     <div class="field">
web       |     30:       <%= f.label :time_zone %>
web       |     31:       <%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.all %>
web       |     32:     </div>
web       |     33:     <div class="grid max-w-sm grid-cols-2 actions gap-x-1 md:gap-x-4 lg:gap-x-8">
web       |     34:       <div class="mb-8">

Having had a look, the special case method that's been defined for time_zone_select might be incorrect:

      def time_zone_select(method, options = {}, html_options = {})
        render_component(
          :time_zone_select, @object_name, method,
          objectify_options(options), @default_html_options.merge(html_options)
        )
      end

It seems that it's currently trying to run objectify_options on the first parameter after method, which is failing because it's an array of TimeZones. Here's some more on what this is expected to accept.

I'm happy to pick up this issue myself.

Spone commented 2 years ago

I'm happy to pick up this issue myself.

Yes, please! Can you start by adding a failing test case to the component spec?

nicolas-brousse commented 2 years ago

76 may resolve this issue about time_zone_select helper. I just merged it in main branch.

If you have the opportunity of test it, let us know if you still have the error.

boardfish commented 2 years ago

I can confirm that it's working now. Thanks for the fix!