Flowdock

Notes posted by pepe_hipolito

RSS feed
December 16, 2014
2 thanks

Group method chain

The group_method parameter can be a string representing a method chain:

grouped_collection_select(:city, :country_id, @continents, 'countries.sort.reverse', :name, :id, :name)

If we were to modify the Country model so we can sort by name:

class Country
  include Comparable

  def <=>(other)
    self.name <=> other.name
  end
end

The above example would have given us the countries sorted by name in descending sequence.