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

Wrong order of collection items for select #593

Open
rivella50 opened this issue Oct 30, 2017 · 4 comments
Open

Wrong order of collection items for select #593

rivella50 opened this issue Oct 30, 2017 · 4 comments

Comments

@rivella50
Copy link

Hi,
i know this issue has been addressed many times, but i still do not see a solution:
When using the following column code in ActiveAdmin the order of the items does not represent my order given in the select statement (it is reordered later after the id keys):

column 'sector' do |i|
    best_in_place i, :sector_id, as: :select, url: admin_sector_path(i), :collection => Sector.order('name asc').map { |f| [f.id, f.name] }
end

Is there a possibility not to allow a reordering for the array given to the collection?

@gmhawash
Copy link

I have the same issue. Any suggestions?

@kmayer
Copy link

kmayer commented Aug 2, 2018

BIP (https://github.com/bernat/best_in_place#usage-of-rails-3-gem) wants the collection as a hash

:collection: If you are using the :select type then you must specify the collection of values it takes as a hash where values represent the display text and keys are the option's value when selected.

e.g. { value => display }

But rails collection_for_select methods want an Array with [[display, value], ...], which just happens to become { display => value } when you call .to_h on the array.

We sort of need a bip helper that will take rails collection and change it to the expected Hash class. Not hard, but annoying.

@kmayer
Copy link

kmayer commented Aug 3, 2018

Here's my terrible hack until a PR

module BestInPlace
  module_function
  def bippify(collection)
    if collection.is_a?(ActiveRecord::Associations::CollectionProxy)
      collection.map{|elt| [elt.id, elt.name]}.to_h
    else
      collection
    end
  end
end

@sqlninja
Copy link

sqlninja commented Oct 3, 2018

Just verified this is fixed on the master branch

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

4 participants