Hello there, I have the following models class Bibliography < ActiveRecord::Base has_and_belongs_to_many :gthemes, :join_table => "gthemes_bibliographies" end class Gtheme < ActiveRecord::Base has_and_belongs_to_many :bibliographies, :join_table => "gthemes_bibliographies" end I want to include in the bibliography edit page a select box with all the gthemes and i want the members of @bibliography.gthemes to be marked as selected I ''m using this in bibliography/_form.rhtml: <%= select(''bibliography'', ''gthemes'' , Gtheme.find(:all).collect{ |gt| [ gt.name, gt.id]}, {}, {:multiple => true}) %> but it doesn''t mark the current gthemes as selected, any ideas? Thanks in advance, Christos --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 13, 4:02 pm, "Trochalakis Christos" <yati...-9B1QEYbJDnYJ0qhBuY+7KQ@public.gmane.org> wrote:> Hello there, > > I have the following models > > class Bibliography < ActiveRecord::Base > has_and_belongs_to_many :gthemes, :join_table => > "gthemes_bibliographies" > end > > class Gtheme < ActiveRecord::Base > has_and_belongs_to_many :bibliographies, :join_table => > "gthemes_bibliographies" > end > > I want to include in the bibliography edit page a select box with all > the gthemes and i want the members of @bibliography.gthemes to be > marked as selected > > I ''m using this in bibliography/_form.rhtml: > > <%= select(''bibliography'', ''gthemes'' , Gtheme.find(:all).collect{ |gt| > [ gt.name, gt.id]}, {}, {:multiple => true}) %> > > but it doesn''t mark the current gthemes as selected, any ideas? > > Thanks in advance, > ChristosI also tried using the form_for helper but the problem still exists <% form_for :bibliography, @bibliography, :url => { :action => "update" } do |f| %> Bgthemes: <%= f.select :gthemes, Gtheme.find(:all).collect {|c| [c.name, c.id]}, {}, {:multiple => true} %> <%= submit_tag ''Save changes'' %> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 13, 5:46 pm, "Trochalakis Christos" <yati...-9B1QEYbJDnYJ0qhBuY+7KQ@public.gmane.org> wrote:> On Mar 13, 4:02 pm, "Trochalakis Christos" <yati...-9B1QEYbJDnYJ0qhBuY+7KQ@public.gmane.org> > wrote: > > > > > Hello there, > > > I have the following models > > > class Bibliography < ActiveRecord::Base > > has_and_belongs_to_many :gthemes, :join_table => > > "gthemes_bibliographies" > > end > > > class Gtheme < ActiveRecord::Base > > has_and_belongs_to_many :bibliographies, :join_table => > > "gthemes_bibliographies" > > end > > > I want to include in the bibliography edit page a select box with all > > the gthemes and i want the members of @bibliography.gthemes to be > > marked as selected > > > I ''m using this in bibliography/_form.rhtml: > > > <%= select(''bibliography'', ''gthemes'' , Gtheme.find(:all).collect{ |gt| > > [ gt.name, gt.id]}, {}, {:multiple => true}) %> > > > but it doesn''t mark the current gthemes as selected, any ideas? > > > Thanks in advance, > > Christos > > I also tried using the form_for helper but the problem still exists > > <% form_for :bibliography, @bibliography, :url => { :action => > "update" } do |f| %> > Bgthemes: <%= f.select :gthemes, Gtheme.find(:all).collect {|c| > [c.name, c.id]}, {}, {:multiple => true} %> > <%= submit_tag ''Save changes'' %> > <% end %>For the record, I didn''t manage to find a "magic way" to do it, but this is a nice and working solution: <%= select_tag ''gthemes[]'', options_from_collection_for_select(@gthemes, ''id'', ''name'', @bibliography.gtheme_ids ), {:multiple => true, :class => "wide"} %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 20, 8:30 pm, "Trochalakis Christos" <yati...-9B1QEYbJDnYJ0qhBuY+7KQ@public.gmane.org> wrote:> For the record, I didn''t manage to find a "magic way" to do it, but > this is a nice and working solution: > > <%= select_tag ''gthemes[]'', > options_from_collection_for_select(@gthemes, ''id'', ''name'', > @bibliography.gtheme_ids ), > {:multiple => true, :class => "wide"} > %>@gthemes = Gtheme.find(:all) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---