-
Notifications
You must be signed in to change notification settings - Fork 160
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
Regression with country_select #11
Comments
I am also getting the same error with simple_form. @tmaier any idea on how to fix or a workaround?
|
Same error here. In my case the error occured while using ActiveAdmin, which uses Formtastic for its forms. @kevinwmerritt: As a quick and dirty workaround the signature of the country_select method in the FormBuilder class (line 176) can be changed from |
@Choppa I had the exact same problem regarding ActiveAdmin and based on this article: http://justinfrench.com/notebook/formtastic-2-preview-custom-inputs, I was able to create the following file and all seems good with the world: |
Hi- Can you try to use the latest version of master and see if this fixes the issue you are having? There was a commit a week or so ago that was supposed to fix this issue. If that doesn't fix it, post back here and I'll see what I can do. |
Hi Jim. Regards, Neil Sent from my iPhone On Aug 26, 2012, at 10:21 PM, Jim Benton [email protected] wrote:
|
Hi Jim. |
@jim Thanks for putting together this gem. I'm using simple form and the following now works:
However, I am also using the nested_form gem and creating nested associations that include the country_code field and require the select helper. While the country select options are generated for each nested association added, the persisted country_code attribute is not preselected in the list. So when the attribute = 'US', 'Afghanistan' always appears because it is the first country in the sorted list. My quick fix for the nested country code fields is this: <%= f.fields_for :sessions do |session| %>
<%= session.input :country_code, :collection => Organization.region_options_for_select(Carmen::Country.all), :label_method => lambda { |i| i[0] }, :value_method => lambda { |i| i[1] } %>
<%= session.link_to_remove "Remove this session" %>
<% end %>
<p><%= f.link_to_add "Add a session", :sessions %></p> def self.region_options_for_select(regions, selected=nil, options={})
options.stringify_keys!
priority_region_codes = options['priority'] || []
region_options = ""
unless priority_region_codes.empty?
unless regions.respond_to?(:coded)
regions = Carmen::RegionCollection.new(regions)
end
priority_regions = priority_region_codes.map do |code|
region = regions.coded(code)
[region.name, region.code] if region
end.compact
unless priority_regions.empty?
region_options += options_for_select(priority_regions, selected)
region_options += "<option disabled>-------------</option>"
end
end
main_options = regions.map { |r| [r.name, r.code] }
main_options.sort!{|a, b| a.first.to_s <=> b.first.to_s}
end I'm not sure if this problem can be addressed in this gem or in nested_form. |
@kevinwmerritt I haven't used nested_forms, but I looked through its code a bit. Nothing lept out at me that would cause this to not work. If you create a form for a session object outside a nested_form, does the same problem occur? |
I ran into this issue today as well. Turns out that it still wouldn't work with nested_form, but the "selected" option in the git version was able to workaround the issue. Thanks for this gem btw. It's awesome! |
country_select
has been a replacement for https://github.com/rails/country_select and therefore API compatible.When I use it now - together with
simple_form
gem - I get the following error message:wrong number of arguments (4 for 3)
The text was updated successfully, but these errors were encountered: