I''m using the following RJS template to spit out a div containing a list of projects: page.replace_html ''results'', ''<div>'' @projects.each do |p| page.insert_html :bottom, ''results'', p.name + "<br/>" end page.insert_html :bottom, ''searchresults'', ''</div>'' page.show ''results'' However, it seems that my first like to insert the <div> tag automatically sticks a </div> closing tag in as well. Is there any way to avoid this, as I''d like the content from the loop to be inserted into this div.
Maybe you can try: html = ''<div>'' @projects.each do |p| html << ''results'' << p.name << ''<br />'' end html << ''searchresults'' << ''</div>'' page.replace_html ''results'', html Something like that. Chris -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dylan Markow Sent: Wednesday, April 19, 2006 4:43 PM To: rails@lists.rubyonrails.org Subject: [Rails] RJS replace_html auto-closing tags I''m using the following RJS template to spit out a div containing a list of projects: page.replace_html ''results'', ''<div>'' @projects.each do |p| page.insert_html :bottom, ''results'', p.name + "<br/>" end page.insert_html :bottom, ''searchresults'', ''</div>'' page.show ''results'' However, it seems that my first like to insert the <div> tag automatically sticks a </div> closing tag in as well. Is there any way to avoid this, as I''d like the content from the loop to be inserted into this div. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think both options are pretty awkward. Put the stuff in a partial and do a replace with :partial render option. -- Ed Frederick -- edwardfrederick.com On 4/19/06, Chris Bruce <cbruce@sleeter.com> wrote:> > Maybe you can try: > > html = ''<div>'' > @projects.each do |p| > html << ''results'' << p.name << ''<br />'' > end > html << ''searchresults'' << ''</div>'' > > page.replace_html ''results'', html > > > Something like that. > > > Chris > > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dylan Markow > Sent: Wednesday, April 19, 2006 4:43 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] RJS replace_html auto-closing tags > > I''m using the following RJS template to spit out a div containing a > list of projects: > > page.replace_html ''results'', ''<div>'' > @projects.each do |p| > page.insert_html :bottom, ''results'', p.name + "<br/>" > end > page.insert_html :bottom, ''searchresults'', ''</div>'' > page.show ''results'' > > However, it seems that my first like to insert the <div> tag > automatically sticks a </div> closing tag in as well. Is there any > way to avoid this, as I''d like the content from the loop to be > inserted into this div. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Oh, and use replace, not replace_html. The first div wasn''t added for you, its just that it''s ''still there'' because you''re just replacing the innards. On 4/19/06, Edward Frederick <epfrederick@gmail.com> wrote:> I think both options are pretty awkward. > > Put the stuff in a partial and do a replace with :partial render option. > > -- > > Ed Frederick -- edwardfrederick.com > > > On 4/19/06, Chris Bruce <cbruce@sleeter.com> wrote: > > > > Maybe you can try: > > > > html = ''<div>'' > > @projects.each do |p| > > html << ''results'' << p.name << ''<br />'' > > end > > html << ''searchresults'' << ''</div>'' > > > > page.replace_html ''results'', html > > > > > > Something like that. > > > > > > Chris > > > > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org > > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dylan Markow > > Sent: Wednesday, April 19, 2006 4:43 PM > > To: rails@lists.rubyonrails.org > > Subject: [Rails] RJS replace_html auto-closing tags > > > > I''m using the following RJS template to spit out a div containing a > > list of projects: > > > > page.replace_html ''results'', ''<div>'' > > @projects.each do |p| > > page.insert_html :bottom, ''results'', p.name + "<br/>" > > end > > page.insert_html :bottom, ''searchresults'', ''</div>'' > > page.show ''results'' > > > > However, it seems that my first like to insert the <div> tag > > automatically sticks a </div> closing tag in as well. Is there any > > way to avoid this, as I''d like the content from the loop to be > > inserted into this div. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
> However, it seems that my first like to insert the <div> tag > automatically sticks a </div> closing tag in as well. Is there any > way to avoid this, as I''d like the content from the loop to be > inserted into this div.How about:> page.replace_html ''results'', ''<div id="projectresults">'' > @projects.each do |p| > page.insert_html :bottom, ''projectsresults'', p.name + "<br/>" > end > page.show ''results''-- Posted via http://www.ruby-forum.com/.