Forum: Ruby on Rails Scoping option_groups_from_collection_for_select

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ed (Guest)
on 2008-11-18 15:42
(Received via mailing list)
How can I scope the options returned by

Method calls look like this:  option_groups_from_collection_for_select
(collection, group_method, group_label_method, option_key_method,
option_value_method, selected_key = nil)

But say I want to limit the results returned by the option_key and
option_value methods to some particular scope?

For instance, using the sample code in rdoc:

  class Continent < ActiveRecord::Base
    has_many :countries
    # attribs: id, name
  class Country < ActiveRecord::Base
    belongs_to :continent
    # attribs: id, name, continent_id

I could get all countries grouped by continent with this:
(@continents, :countries, :name, :id, :name, 3)

But say I had another class called Ally:

  class Alliance < ActiveRecord::Base
    has_many :countries   #reciprocal belongs_to added to country
    #attribs: id, name

How could I scope the OGFCFS call so that it only listed countries
belonging to a particular alliance?
This topic is locked and can not be replied to.