Patrick Aljord
2006-Aug-16 20:16 UTC
[Rails] how to update a collection_select from another
I have two collection_select in my list.rhtml: <%= collection_select (:region, :id, @regionall, :id, :title,html_options={:onChange => "new Ajax.Updater(''related_provinces'',''/categories/related_provinces/" + "?id=''+this[this.selectedIndex].value, {asynchronous:true, evalScripts:true});"}) %><br> <%= render :partial => "related_provinces" %> This is my partial: _related_provinces.rhtml: <%= collection_select(:region, :id, @provinces, :id, :title) %> category_controller.rb: def list @regionall = Region.find(:all, :conditions => [ "parent_id = ?", ''1''],:order=>"id") @provinces = Region.find(:all, :conditions => [ "parent_id = ?", @region.parent.id],:order=>"id") end The problem is that it doesn''t even display the onChange javascript code: <select id="region_id" name="region[id]"><option value="2">bla1</option> <option value="3">bla2</option> <option value="4">bla3</option></select><br> <select id="region_id" name="region[id]"> <option value="61" selected="selected">blop1</option> <option value="62">blop2</option> <option value="68">blop3</option></select> Could you please tell me first why my JS code isn''t display and second if the ajax update JS code is correct? :) Thanx in adance Pat
Try reading this thread; http://www.nabble.com/forum/ViewPost.jtp?post=4302805&framed=y I was trying to do a similar thing, and the guys were very helpful. Good Luck. Patrick Aljord wrote:> > I have two collection_select in my list.rhtml: > <%= collection_select (:region, :id, @regionall, :id, > :title,html_options={:onChange => "new > Ajax.Updater(''related_provinces'',''/categories/related_provinces/" + > "?id=''+this[this.selectedIndex].value, > {asynchronous:true, evalScripts:true});"}) %><br> > <%= render :partial => "related_provinces" %> > > This is my partial: > _related_provinces.rhtml: > <%= collection_select(:region, :id, @provinces, :id, :title) %> > > > category_controller.rb: > def list > @regionall = Region.find(:all, :conditions => [ "parent_id = ?", > ''1''],:order=>"id") > @provinces = Region.find(:all, :conditions => [ "parent_id = ?", > @region.parent.id],:order=>"id") > end > > The problem is that it doesn''t even display the onChange javascript code: > > <select id="region_id" name="region[id]"><option value="2">bla1</option> > <option value="3">bla2</option> > <option value="4">bla3</option></select><br> > <select id="region_id" name="region[id]"> > <option value="61" selected="selected">blop1</option> > <option value="62">blop2</option> > <option value="68">blop3</option></select> > > Could you please tell me first why my JS code isn''t display and second > if the ajax update JS code is correct? :) > > Thanx in adance > > Pat > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- View this message in context: http://www.nabble.com/how-to-update-a-collection_select-from-another-tf2117540.html#a5839937 Sent from the RubyOnRails Users forum at Nabble.com.