ruby - Rails - grouped_collection_select -
i'm trying grouped_collection_select following
class user has_many :pages, :through => pages_users end class page has_many :users, :through => pages_users # name - string # type - string end class pagesuser < activerecord::base belongs_to :page belongs_to :user end and want drop down grouped type name underneath. example i've seen city/country/continent, isn't helpful i'd like. what's best way of doing this? think want ...
<%= grouped_collection_select(:user, :page_id, user.pages, :type, :name, ) %> but isn't correct.
any thoughts?
edited show actual relationships through pages_users table.
here's ended ...
<%= select_tag 'page_id', grouped_options_for_select(page.for_select) %> where page.for_select looks ...
def for_select { 'type 1' => type1.map { |p| [p.name, p.id] }, 'type 2' => type2.map { |p| [p.name, p.id] } } end hope helps else.
Comments
Post a Comment