Ruby On Rails in UA Icon_home Главная Add to bookmarks Translate translate Profile Войти
Регистрация Форум Блоги Пользователи Список джемов Rails проекты      Поиск   

Ruby On Rails in UA/Программирование на ROR/option_groups_from_collection_for_select/RE: option_groups_from_collection_for_select

2008-10-14 11:19:15 Ответить  
vintyara
Vitaly
Адрес: Odessa
Сообщений: 57
Регистр: 2008-07-23
его блог 0 сообщ.
RE: option_groups_from_collection_for_select
  •  
Наверное никто не может понять что это за фигня, потому на всякий случай приведу выдержку из доки:

option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil)

Returns a string of tags, like options_from_collection_for_select, but groups them by tags based on the object relationships of the arguments.

Parameters:

* collection - An array of objects representing the tags.
* group_method - The name of a method which, when called on a member of collection, returns an array of child objects representing the tags.
* group_label_method+ - The name of a method which, when called on a member of collection, returns a string to be used as the label attribute for its tag.
* option_key_method - The name of a method which, when called on a child object of a member of collection, returns a value to be used as the value attribute for its tag.
* option_value_method - The name of a method which, when called on a child object of a member of collection, returns a value to be used as the contents of its tag.
* selected_key - A value equal to the value attribute for one of the tags, which will have the selected attribute set. Corresponds to the return value of one of the calls to option_key_method. If nil, no selection is made.

Example object structure for use with this method:

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

Sample usage:

option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)

Possible output:

Note: Only the and tags are returned, so you still have to wrap the output in an appropriate tag.
Назадназад Новыйновый Ответитьответить
Ключевые слова:
Гости: 83 Онлайн: Vitaly ,
Rambler's Top100
О проекте по всем вопросам обращайтесь на support
Rubyclub.com.ua Copyright © 2007 - 2008