Forum: Ruby on Rails Best way to render stuff inside a div and pass variables?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cbfcc40b0b4e6091eb8620dcd4b0de6d?d=identicon&s=25 André Guedes (crei0)
on 2006-05-31 16:35
For example, I want to click a button or a link, then without leaving
the page, i want the content of a <div> to change accordingly if I click
the link1 I want the content1 to show up inside the <div>here</div>

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 Development 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?
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2006-05-31 16:53
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... :-)
This topic is locked and can not be replied to.