How can I scope the options returned by
option_groups_from_collection_for_select?
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
end
class Country < ActiveRecord::Base
belongs_to :continent
# attribs: id, name, continent_id
end
I could get all countries grouped by continent with this:
option_groups_from_collection_for_select
(@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
end
How could I scope the OGFCFS call so that it only listed countries
belonging to a particular alliance?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---