When a controller action is called via XHR (XmlHttpRequest), the action will look for a .rjs template first, then a .rhtml template if not available.
To skip using the .rjs template, include a render(:update) {|page| <block code> } call to perform updates.
def toggle_showall
render(:update) do |page|
page[:fb_content].replace_html "just text? ripoff!"
page[:flash_box].visual_effect :blind_down, :duration => 0.25
end
end
We use page as a hash to reference elements by id from the originating page.
page[:fb_content]
Then perform the updates to the element. Here we're replacing the contents of the element with id of "fb_content" with the string of text.
page[:fb_content].replace_html "just text? ripoff!"
You can render anything you could normally using a render call, example, some partial.
page[:fb_content].replace_html :partial => "shared/some_partial"
If the partial you're calling has instance vars you need to fill before, just include them before the render(:update) block and they'll be available to the partial during rendering.
Here we execute scriptaculous' Effect.BlindDown on element 'flash_box' with option of duration of .25 seconds.
page[:flash_box].visual_effect :blind_down, :duration => 0.25
There are plenty of other methods you can call on a page element. Refer to the Agile WebDev PDF for more details.