# Displaying content using rails

**URL:** <https://www.ruby-forum.com/t/displaying-content-using-rails/162295>\
**Category:** Rails\
**Created:** [March 8, 2009, 7:27am UTC](https://www.ruby-forum.com/t/displaying-content-using-rails/162295 "2009-03-08T07:27:39Z")\
**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, 7:27am UTC](https://www.ruby-forum.com/t/displaying-content-using-rails/162295/1 "2009-03-08T07:27:39Z")

</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-rails/162295/2 "2009-03-08T17:49:19Z")

</div>

Hi Vishy,

On Sat, 2009-03-07 at 22:26 -0800, vishy wrote:

> 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:

I recommend you pick up Cody F.'s ‘RJS Templates for Rails’ short  
cut at O’Reilly ([RJS Templates for Rails [Book]](http://oreilly.com/catalog/9780596528096/)) $10 will  
get you a PDF download that will get you well down the road on Ajax for  
Rails.

HTH,  
Bill
