# Displaying content using AJAX

**URL:** <https://www.ruby-forum.com/t/displaying-content-using-ajax/162314>\
**Category:** Rails\
**Created:** [March 8, 2009, 4:06pm UTC](https://www.ruby-forum.com/t/displaying-content-using-ajax/162314 "2009-03-08T16:06:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 8, 2009, 4:06pm UTC](https://www.ruby-forum.com/t/displaying-content-using-ajax/162314/1 "2009-03-08T16:06:00Z")

</div>

All,  
I am trying to implement some ajax functionality on my web site. I  
have a list of links and each link have many items associated with  
it.  
For example, “My Netflix queue” link is connected to 10 movies  
(items). Now, I am trying to display a table with these items when  
the  
user clicks on the link. I have other links and corresponding items  
on  
my page. I want to do all this using Ajax. But have not been able to  
implement this so far. The code that I have used is given below:

[//link.html.erb](https://link.html.erb) (:link passes the link\_is to the rjs which gets all  
//the items for that link)

\<% for link in @links %\>

 \<%= link\_to\_remote link.name, :url =\> { :action =\> 'show\_items', :link =\> link.id} %\> 

\<% end %\>

//this is where I want to display the items

\<% if params[:link] %\>

\<% for item in @item %\> \<% end %\>

| ![]()  
 \<%= item.name %\> |

\<% end %\>

//RJS Template (show\_items.js.rjs)  
//@items has all the items for that link. I have verified using the  
//debug statement. Now I need to pass the @items variable to the view  
//so that the items are displayed. But thats where I am erring.

link = params[:link]  
@items = Item.find\_all\_by\_link\_id(params[:link])  
logger.debug "Items : " + @items.inspect  
page.replace\_html :items, @items, :object =\> @items

[//controller.rb](https://controller.rb)  
def link  
@links = Link.find(:all)  
end  
Any help will be greatly appreciated.  
Thanks,  
vishy

---

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 8, 2009, 5:49pm UTC](https://www.ruby-forum.com/t/displaying-content-using-ajax/162314/2 "2009-03-08T17:49:20Z")

</div>

On 8 Mar 2009, at 15:04, vishy wrote:

> //this is where I want to display the items
> 
> \<% if params[:link] %\>

This doesn’t look right. The placeholder div with id items should  
always be there (or else your rjs will have nothing to insert into).

> \<% end %\>

You should be naming a partial here to render.

Fred
