formtastic-bootstrap icon indicating copy to clipboard operation
formtastic-bootstrap copied to clipboard

Doesn't work with country_select version 2.0.0+

Open pjg opened this issue 10 years ago • 5 comments

country_select version 2.0.0 (not yet released) introduces a number of big changes. One among them is a different syntax for country_select view helper:

def country_select(method, options = {}, html_options = {})

(source)

Which is incompatible with formtastic-bootstrap's invocation:

builder.country_select(method, priority_countries, input_options, input_html_options)

(source)

The exact same issue is present on latest formtastic gem as well: https://github.com/justinfrench/formtastic/issues/1008

pjg avatar Mar 13 '14 13:03 pjg

The workaround is to put this into config/initializers/formtastic_bootstrap.rb:

class FormtasticBootstrap::Inputs::CountryInput
  def to_html
    bootstrap_wrapping do
      builder.country_select(method, input_options, form_control_input_html_options)
    end
  end
end

(BTW for formtastic-bootstrap version < 3.0.0 the last param should be called input_html_options instead of form_control_input_html_options).

pjg avatar Mar 13 '14 13:03 pjg

Would you prefer if we force the newer version in our gem requirements, or is there a clean way to be compatible to both versions?

Monkey patching in an initializer is not an ideal long term solution.

sodabrew avatar Mar 13 '14 16:03 sodabrew

We definitely should make it backward compatible.

We could base it on CountrySelect::VERSION.to_i >= 2 or on builder.method(:country_select).arity == 3. What do you think?

jtomaszewski avatar Mar 13 '14 18:03 jtomaszewski

country_select is not in the gemspec (not here nor in the base formtastic gem), formtastic supports it only if the gem is installed (bundled). If it's not, it will raise but only when attempting to use the country input type.

In other words, I think that it's necessary to be backwards compatible with the soon-to-be old version.

I'm perfectly fine with version constrains and different behaviour based on that.

pjg avatar Mar 13 '14 19:03 pjg

Could you test this with the newly posted formtastic-bootstrap 3.1.0, which works with the new Formtastic class finder and let me know if it works / still broken?

sodabrew avatar Jan 11 '15 01:01 sodabrew