Best way to render stuff inside a div and pass variables?


For example, I want to click a button or a link, then without leaving
the page, i want the content of a

to change accordingly if I click
the link1 I want the content1 to show up inside the

I made it possible by using:
<%= render :partial => “icons”, :collection => @packages, :locals => {
:@icon_name => “-add-black-” } %>
( Passing a string to the render partial… )
But how do you call a “render :partial …” using a link or a button…

In the Agile Web D. with Rails book, the shopping cart is made
using i think a “component”… but I heard that components have a big
performance drop…

So my question is whats the best way?

  1. Using a link that then activates a render :partial?
  2. Using a component?
  3. Other?


try the link_to_remote helper

Lets you call an action via ajax and target a page element to display
the results in.

Create an action that just returns the partial and call that. You’ll
also need to tell your controller not to render a layout for that
action, by adding and exception to your controller:

layout “layouts/thelayoutyourusing”,
:except => [:that_thing_your_calling_via_ajax]

Hope that helps… :slight_smile: