views:

270

answers:

1

From the documentation for link_to_remote

The result of that request can then be inserted into a DOM object whose id can be specified with options[:update]. Usually, the result would be a partial prepared by the controller with render :partial.

For example, one would do this:

<%= link_to_remote( "Some link text", :url => url, :method => method, :update => 'name_of_partial' %>

Is there a way to pass a :locals hash to the partial (in the example above, 'name_of_partial') similar to when you would render it using "render :partial"?

+2  A: 

You don't quite understand. The :update argument is the html id of the element that will have its contents replaced by the contents of the result of this ajax call.

<div id="ajax_message"></div>
<%= link_to_remote 'click me',
                   :url => my_ajax_action_path,
                   :update => 'ajax_message' %>

The partial in question is rendered in response to the ajax request in your controller.

def my_ajax_action
  @my_object = MyOobject.find(params[:id]) #or something
  render :partial => 'my_object',
         :locals => { :my_object => @my_object }
end

The resulting response body is then shoved into your previously named element via the :update argument.

Squeegy
Thanks for clearing that up for me!
Readonly