# Render partial

**URL:** <https://www.ruby-forum.com/t/render-partial/118692>\
**Category:** Rails\
**Created:** [October 30, 2007, 3:35am UTC](https://www.ruby-forum.com/t/render-partial/118692 "2007-10-30T03:35:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmygoogle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c67d28/32.png) [@jimmygoogle](https://www.ruby-forum.com/u/jimmygoogle)\
**Post date:** [October 30, 2007, 3:35am UTC](https://www.ruby-forum.com/t/render-partial/118692/1 "2007-10-30T03:35:11Z")

</div>

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 %\>

\<%= render :partial =\> "show", :id =\> item.id %\>

---

<div class="post-metadata">

**Author:** ![jimmygoogle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c67d28/32.png) [@jimmygoogle](https://www.ruby-forum.com/u/jimmygoogle)\
**Post date:** [October 30, 2007, 4:25am UTC](https://www.ruby-forum.com/t/render-partial/118692/2 "2007-10-30T04:25:27Z")

</div>

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](http://api.rubyonrails.org) for more information

---

<div class="post-metadata">

**Author:** ![jimmygoogle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c67d28/32.png) [@jimmygoogle](https://www.ruby-forum.com/u/jimmygoogle)\
**Post date:** [November 2, 2007, 12:33am UTC](https://www.ruby-forum.com/t/render-partial/118692/3 "2007-11-02T00:33:49Z")

</div>

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.
