读书人

二级上拉选择框option_groups_from_co

发布时间: 2012-09-13 09:51:52 作者: rapoo

二级下拉选择框option_groups_from_collection_for_select

class Group < ActiveRecord::Base  has_and_belongs_to_many :users  # attribs: id, nameendclass User < ActiveRecord::Base  has_and_belongs_to_many :groups  # attribs: id, nameendclass Delivery < ActiveRecord::Base  belongs_to :recipient, :class_name => "User", :foreign_key => :recipient_id  # attribs: id, name, recipient_idend
?

option_groups_from_collection_for_select(Group.all, :users, :name, :id, :name, @delivery.recipient_id)

?

效果:

金工组-------------------group_name

? ?用户1------------------user_name

铆焊组

? ?用户2

? ?用户3

?

api说明:

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?<option>?tags, like?options_from_collection_for_select, but groups them by?<optgroup>?tags based on the object relationships of the arguments.

Parameters:

读书人网 >编程

热点推荐