iは1ページ(2グループに属する1つのメッセージ)collection_select選択された値
<%=
collection_select(:message,:group_ids, Group.find(:all),:id, :title, {}, {:name=>'message[group_ids][]'})
%>
<%=
collection_select(:message,:group_ids, Group.find(:all),:id, :title, {}, {:name=>'message[group_ids][]'})
%>
上の2つの同一のcollection_selectsを有するcollection_selectを使用して2つの異なる選択された値を設定することが可能ですか?
編集:
私は
<%
@message.group_id=5
%>
<%=
collection_select(:message,:group_id, Group.find(:all),:id, :title, {}, {:name=>'message[group_ids][]'})
%>
<%
@message.group_id=6
%>
<%=
collection_select(:message,:group_id, Group.find(:all),:id, :title, {}, {:name=>'message[group_ids][]'})
%>
ような何かをしたが、もちろん、それは
EDIT2を仕事とする方法行方不明のエラーを与えていない必要があるだろうと思います。
collection_selectで行うことはできません。グループにメソッドがない場合は、毎回単一のgroup_idを返します。私がなってしまったものを
は、あなたがそうのようなあなたのモデルとの関係を設定する必要があり
select_tag 'message[group_ids][]', "<option></option>"+options_from_collection_for_select(Group.find(:all), 'id', 'title',group1.id)
select_tag 'message[group_ids][]', "<option></option>"+options_from_collection_for_select(Group.find(:all), 'id', 'title',group2.id)
最初の質問は、これを試してみる理由です。 –
質問が例でしたが、実際に何をしようとしているのですか? <% @ message.groups.each do | group | %> collection_select(:message、group.id、Group.find(:all)、:id、 %> <% エンド %> メッセージがグループとHABTM関係を持っているので、それはgroup_ids方法がありますが、collection_selectは私がgroup.idを使用することができ、またはしない:選択したキーワードコメントを おかげでなく、私は別のソリューションを使用するつもりだと思う(私は質問に編集を加えた)。 –