Skip to content

Instantly share code, notes, and snippets.

@detomastah
Created December 20, 2012 15:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save detomastah/4345898 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.transaction do
Category.all.each do |c|
ordered_configs = c.search_attribute_configs.
joins(:search_attribute).
order("cnet_search_attributes.name").
select("DISTINCT search_attribute_configs.id, cnet_search_attributes.name")
ordered_configs.each_with_index do |sa_config, index|
sa_config = SearchAttribute::Config.find(sa_config.id)
sa_config.update_attribute(:position, index + 1)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment