I have a quick question about render partial functionality. I have an array of items and I am printing out the item and its link - I would like the link when clicked to display the content below it. I have this working so it goes to another page but I would like to print the contents of _show.rhtml in a div tag below it. I guess the issue I am having is how do I get item.id to be passed below? <% @items.each do |item| %> #this links to show.rhtml and renders the content it should <%= link_to item.title, :action => "show", :id => item.id %> <% end %> <div class="content"> <%= render :partial => "show", :id => item.id %> </div> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
you need to either use an ajax call to update the contents of the page with the partial, or you can render all the partials and then use javascript to toggle (show/hide) the container div. Ajax is probably the better solution, since you''re loading content only when the user requests it, rather than the Javascript approach which requires you to load the information for every item at once. If you want to use the ajax method, you''ll need to use link_to_remote instead of simply link_to, then define an Ajax callback method in your controller, and then call render :update do |page| page.replace.html ''my_div'', ''my_partial_name'' end search for link_to_remote on api.rubyonrails.org for more information On 10/29/07, jimmygoogle <jtbutler78-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > I have a quick question about render partial functionality. I have an > array of items and I am printing out the item and its link - I would > like the link when clicked to display the content below it. I have > this working so it goes to another page but I would like to print the > contents of _show.rhtml in a div tag below it. I guess the issue I am > having is how do I get item.id to be passed below? > > <% @items.each do |item| %> > > #this links to show.rhtml and renders the content it should > <%= link_to item.title, :action => "show", :id => item.id %> > > <% end %> > > <div class="content"> > <%= render :partial => "show", :id => item.id %> > </div> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I just around to looking at it now but ''link_to_remote'' is exactly what I needed. It works like a charm, thanks a lot. On Oct 29, 11:24 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> you need to either use an ajax call to update the contents of the page > with the partial, or you can render all the partials and then use > javascript to toggle (show/hide) the container div. Ajax is probably > the better solution, since you''re loading content only when the user > requests it, rather than the Javascript approach which requires you to > load the information for every item at once. > > If you want to use the ajax method, you''ll need to use link_to_remote > instead of simply link_to, then define an Ajax callback method in your > controller, and then call > > render :update do |page| > page.replace.html ''my_div'', ''my_partial_name'' > end > > search for link_to_remote on api.rubyonrails.org for more information > > On 10/29/07, jimmygoogle <jtbutle...-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote: > > > > > I have a quick question about render partial functionality. I have an > > array of items and I am printing out the item and its link - I would > > like the link when clicked to display the content below it. I have > > this working so it goes to another page but I would like to print the > > contents of _show.rhtml in a div tag below it. I guess the issue I am > > having is how do I get item.id to be passed below? > > > <% @items.each do |item| %> > > > #this links to show.rhtml and renders the content it should > > <%= link_to item.title, :action => "show", :id => item.id %> > > > <% end %> > > > <div class="content"> > > <%= render :partial => "show", :id => item.id %> > > </div>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---