mjbellantoni / formtastic-bootstrap

Formtastic form builder to generate Twitter Bootstrap-friendly markup.
MIT License
444 stars 217 forks source link

Doesn't work with country_select version 2.0.0+ #101

Open pjg opened 10 years ago

pjg commented 10 years ago

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 commented 10 years ago

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).

sodabrew commented 10 years ago

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.

jtomaszewski commented 10 years ago

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?

pjg commented 10 years ago

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.

sodabrew commented 9 years ago

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?