I have a view where I render a partial over a collection. Each instance of the partial includes a <div> with an id specific to that instance. Inside the partial, there is a select tag for "year". I''m trying to change some of the contents of the partial when user changes the year. I''m using this in the view: <%= select_tag :year, options_for_select(recent_years, @year), :onchange => remote_function( :url => {:update => dom_id(product), :action => ''year_selection_changed'', :product_id => product.id, :company_id => @company.id, :update_div_id => dom_id(product) }, :with => "''year=''+value") -%> that dom_id(product) is a helper that gives the div a unique "id". The same helper is used to give the div its unique id, and in the code above to specify which part of the page we are going to update. In my controller: def year_selection_changed ... render :update do |page| page.replace_html params[:update_div_id], :partial => ''product'', :object => @product end end The problem is that instead of replacing the content of the div in question, it just adds the newly rendered stuff above what was already there. It is acting the same as it would if you changed the part of the select code: :url => {:update => dom_id(product), to something that doesn''t exist: :url => {:update => "fred", Anybody know how to fix this thing so it will replace the div instead of adding to it? many thanks, jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 13 Feb 2008, at 08:04, Jeff Pritchard wrote:> > that dom_id(product) is a helper that gives the div a unique "id". The > same helper is used to give the div its unique id, and in the code > above > to specify which part of the page we are going to update. > > In my controller: > def year_selection_changed > ... > render :update do |page| > page.replace_html params[:update_div_id], :partial => ''product'', > :object => @product > end > end >At least part of the problem is that you are doing render :update => ''...'' which means ''please insert the result of this ajax call into this div'' and you are doing a render :update (ie you are generating javascript to replace some html). What happens if you change your controller so that instead it just renders the appropriate partial (ie year_selection_changed.html.erb is just <%= render :partial => ''product'' %> Fred> The problem is that instead of replacing the content of the div in > question, it just adds the newly rendered stuff above what was already > there. It is acting the same as it would if you changed the part of > the > select code: > :url => {:update => dom_id(product), > to something that doesn''t exist: > :url => {:update => "fred", > > Anybody know how to fix this thing so it will replace the div > instead of > adding to it? > > many thanks, > jp > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 13 Feb 2008, at 08:04, Jeff Pritchard wrote: > >> page.replace_html params[:update_div_id], :partial => ''product'', >> :object => @product >> end >> end >> > > At least part of the problem is that you are doing render :update => > ''...'' which means ''please insert the result of this ajax call into > this div'' and you are doing a render :update (ie you are generating > javascript to replace some html). > > What happens if you change your controller so that instead it just > renders the appropriate partial (ie year_selection_changed.html.erb is > just <%= render :partial => ''product'' %> > > FredWow, I must be clairvoyant this evening, how did I know to use "fred" as my unknown div id? Anyway, wouldn''t it need to be: <%= render :partial => ''product'', :object => @product %> so the partial knows which product to render? BTW, my take on the render :update thing is that it is acting like it doesn''t recognized the div id in the :update parameter of the URL. With it being a "remote_function" call, I was thinking one would need to do an ajax render :update rather than a simple render. I reckon if it recognized the div''s id and actually did the :update that was requested, then it would indeed need just the render :partial... Anyway, as you can see, this stuff has always confused me somewhat. thanks, jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 13 Feb 2008, at 08:59, Jeff Pritchard wrote:> > Frederick Cheung wrote: >> On 13 Feb 2008, at 08:04, Jeff Pritchard wrote: >> >>> page.replace_html params[:update_div_id], :partial => ''product'', >>> :object => @product >>> end >>> end >>> >> >> At least part of the problem is that you are doing render :update => >> ''...'' which means ''please insert the result of this ajax call into >> this div'' and you are doing a render :update (ie you are generating >> javascript to replace some html). >> >> What happens if you change your controller so that instead it just >> renders the appropriate partial (ie year_selection_changed.html.erb >> is >> just <%= render :partial => ''product'' %> >> >> Fred > > Wow, I must be clairvoyant this evening, how did I know to use > "fred" as > my unknown div id? > > Anyway, wouldn''t it need to be: > <%= render :partial => ''product'', :object => @product %> > > so the partial knows which product to render? >If you don''t tell it what to render it will try @product since the partial is called product> BTW, my take on the render :update thing is that it is acting like it > doesn''t recognized the div id in the :update parameter of the URL. > With > it being a "remote_function" call, I was thinking one would need to do > an ajax render :update rather than a simple render. I reckon if it > recognized the div''s id and actually did the :update that was > requested, then it would indeed need just the render :partial... >the fundamental thing to remember is that link_to_remote :update => ''foo'' says ''dump the body of the response in the div with id foo'' and render :update do |page| ... end generates javascript. With that in mind it should be obvious what is what. Fred> Anyway, as you can see, this stuff has always confused me somewhat. > > thanks, > jp > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 13 Feb 2008, at 08:04, Jeff Pritchard wrote: > What happens if you change your controller so that instead it just > renders the appropriate partial (ie year_selection_changed.html.erb is > just <%= render :partial => ''product'' %> > > FredSo with this in there, and supplying the @product as I mentioned in my last reply, it does precisely nothing, and the log says it did the expected render. Just nothing happens on the screen at all. thanks, jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 13 Feb 2008, at 09:28, Jeff Pritchard wrote:> > Frederick Cheung wrote: >> On 13 Feb 2008, at 08:04, Jeff Pritchard wrote: >> What happens if you change your controller so that instead it just >> renders the appropriate partial (ie year_selection_changed.html.erb >> is >> just <%= render :partial => ''product'' %> >> >> Fred > > So with this in there, and supplying the @product as I mentioned in my > last reply, it does precisely nothing, and the log says it did the > expected render. Just nothing happens on the screen at all.Install firebug and you''ll be able to see exactly what the browser is sending and exactly what is being returned by your app.> > > thanks, > jp > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 13 Feb 2008, at 09:28, Jeff Pritchard wrote: > >> So with this in there, and supplying the @product as I mentioned in my >> last reply, it does precisely nothing, and the log says it did the >> expected render. Just nothing happens on the screen at all. > > Install firebug and you''ll be able to see exactly what the browser is > sending and exactly what is being returned by your app.Thanks for the help guys, firebug showed everything working as expected, and still nothing happening on the screen. Stared at it some more and looked at some other times I have used this and finally realized that my ":update" was erroneously tucked inside the :url hash. pulled that out and now its working fine. thanks, jp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---