Forum: Ruby on Rails (dup) Ajaxified Select List

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3bbf721451f1a9df7f1eb7cbce05b63e?d=identicon&s=25 orsini (Guest)
on 2005-11-26 23:45
(Received via mailing list)
(woops!, sent again in it's own thread, sorry for the dup)

Hi,

I'm trying to dynamically add items to a select list with Ajax. I'm
displaying the options of the list with render_partial_collection and
passing it a list of galleries. When the page is hit initially the
drop-down list renders correctly (with galleries from my db). When I
submit my form (using form_remote_tag) with the new gallery to add, my
controller takes a turn at rendering the same partial, but spits out
plain text within the select tags instead of option elements. Right, so
here's the code...

___controller: test_controller.rb___
class TestController < ApplicationController
   def index
     @galleries = Gallery.find(:all).map { |g| g.name }
   end
   def add
     @newGal = Gallery.new
     @newGal.name = @params['new_gallery']
     @newGal.save
     @galleries = Gallery.find(:all).map { |g| g.name }
     render_partial_collection 'shared/gallery', @galleries
   end
end


___partial: shared/_gallery.rhtml___
<option><%= gallery %></option>


___view: index.rhtml___
<%= form_remote_tag(:update => "update_galleries",
                     :complete => evaluate_remote_response,
                     :url => { :action => :add } ) %>
   <%= text_field_tag :new_gallery %>
   <%= submit_tag "Submit" %>
<%= end_form_tag %>

<select id="update_galleries">
   <%= render_partial_collection 'shared/gallery', @galleries %>
</select>

What's interesting to me is that if I use a div tag instead of a
select, and add, say, a list of links using my partial, the html is
retained. Perhaps I've just been staring at this too long this morning.
Ideas?

Thanks,
Rob
4a9451ddc52cb4bb94f216e431ede41e?d=identicon&s=25 orsini (Guest)
on 2005-11-27 00:38
(Received via mailing list)
> I'm trying to dynamically add items to a select list with Ajax. I'm
> displaying the options of the list with render_partial_collection and
> passing it a list of galleries. When the page is hit initially the
> drop-down list renders correctly (with galleries from my db). When I
> submit my form (using form_remote_tag) with the new gallery to add, my
> controller takes a turn at rendering the same partial, but spits out
> plain text within the select tags instead of option elements.

I just found that it works fine in Safari but not in Firefox. Troubling.
This topic is locked and can not be replied to.