Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Country input crashes with country_select >= 9.0.0 #1381

Open
padde opened this issue Feb 19, 2024 · 2 comments
Open

Country input crashes with country_select >= 9.0.0 #1381

padde opened this issue Feb 19, 2024 · 2 comments

Comments

@padde
Copy link

padde commented Feb 19, 2024

When using with country_select >= 9.0.0 we get the following error:

ActionView::Template::Error
wrong number of arguments (given 4, expected 1..3)

This is due to the method signature of country_select form builder having changed via countries/country_select@021845d

I could work on a fix for this however I would like to discuss first, should both the old and the new version be supported, or should an error be raised for versions <= 9.0.0, effectively forcing an upgrade?

@padde
Copy link
Author

padde commented Feb 19, 2024

PS: For anyone else having this problem - as a temporary workaround, we have added the following custom input which uses the new method signature:

module Formtastic
  module Inputs
    class CustomCountryInput
      include Base

      CountrySelectPluginMissing = Class.new(StandardError)

      def to_html
        raise CountrySelectPluginMissing, 'To use the :country input, please install a country_select plugin, like this one: https://github.com/stefanpenner/country_select' unless builder.respond_to?(:country_select)

        input_wrapping do
          label_html <<
            builder.country_select(method, input_options.reverse_merge(priority_countries:), input_html_options)
        end
      end

      def priority_countries
        options[:priority_countries] || builder.priority_countries
      end
    end
  end
end

then used it as

f.input :country, as: :custom_country, ...

leoarnold added a commit to leoarnold/formtastic that referenced this issue Feb 22, 2024
The `country_select` v2 syntax was introduced in
[August 2014](https://github.com/countries/country_select/blob/19072737cc2b2a12723b2dd273263b71fd5395ed/UPGRADING.md).

Now, 10 years and 7 major versions later, the project
[dropped support for v1 syntax](countries/country_select#224)
starting with v9.

This change adapts `formtastic` to the new method signature,
removes all claims that it supports v1 syntax,
and updates the URLs to the new home under a new maintainer.
@AJFaraday
Copy link

@padde Thank you for documenting this issue and the workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants