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

Sort order in country_select #7

Closed
lacco opened this issue Jun 4, 2012 · 4 comments
Closed

Sort order in country_select #7

lacco opened this issue Jun 4, 2012 · 4 comments

Comments

@lacco
Copy link

lacco commented Jun 4, 2012

ruby 1.9.3p194
rails 3.2.3
carmen-rails 1.0.0.beta3

I am a little confused about the sort order of the countries generated by country_select. The sorting algorithm from https://github.com/jim/carmen-rails/blob/ada9fc20b65123629fb0831b5997f81f9bfb2a5e/lib/carmen/rails/action_view/form_helper.rb#L88 behaves like this on the command line:

Carmen::World.instance.subregions.sort{|a, b| a.name.unpack('U').to_s <=> b.name.unpack('U').to_s}.map{|r| [r.name, r.name.unpack('U').to_s]}
 => [... ["Greece", "[71]"], ["Germany", "[71]"], ["Guatemala", "[71]"] ... ]

As you can see, the order isn't correct because all countries with "G" have the same sort key "[71]".

@lacco
Copy link
Author

lacco commented Jun 4, 2012

I backported my code to carmen 0.2.13, and now the sorting is fine.

@jim
Copy link
Collaborator

jim commented Jun 5, 2012

You're right, this is an issue.

I think the way to go with this is to define <=> on Carmen::Country, and then have the view helper just call sort on the collection. I'll take a stab at this.

@rdsoze
Copy link
Contributor

rdsoze commented Jun 22, 2012

Removing the unpack('U') puts the countries in the correct sort order. A bit confused here about what unpack('U') does ..

@jim
Copy link
Collaborator

jim commented Jun 25, 2012

Fixed in master.

@jim jim closed this as completed Jun 25, 2012
jesusdp pushed a commit to designerpages/carmen-rails that referenced this issue May 27, 2020
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

3 participants