Not an ajax call. Does it only work for an ajax call?
Yes. if you use render :update it returns some javascript. The
prototype (and jquery etc.) libraries know to execute that javascript,
but just a generic browser page load doesn't
If you want to replace a page fragment you have to use an ajax request
(although you don't have to use render :update):
if you have link_to_remote 'Click me', :update => 'some_id', :url =>
{:action => 'foo'}
and then
def foo
render ...
end
Then the results of that render will get stuck in the page element
with id some_id. You only need the render :update / rjs mechanism to
update multiple things on the page.
Well the “page fragment” is a div with a partial in it. I need to be able to make a regular call and update the div with the partial. I have a select box used to go to a page. I need to be able to change out what is in the div.
$('shelfcards').update(<fieldset>....</fieldset>)
Clearly that isn't legal javascript because you've just dumped in a
chunk of html, whereas you need a string containing html
Do note, that this is not really ajax. The point of ajax, and more
importantly the use of rendering a partial is that when you make the
request you are not reloading the entire page, but rather using
javascript to send a request to the server in the background while the
existing page doesn't reload. Using the javascript
document.location.href call makes a full page load (regular html page
request). To implement this instead with ajax you might instead have
the select element inside a form, which you would post to a controller
action (you can send the form using the onchange option for the select
tag).
The reason for this is because the partial contains only part of a
valid html page as Fred mentioned, using this method the controller
action responding to the call, can then respond with something like
page.replace_html :partial => "my_partial", which is some javascript
telling the page that send the request to replace part of it's old
html with the new version (sent as a string inside the javascript).
Doing it this way will get teh ajax request working correctly (a true
ajax call, with an rjs or render(:update) controller response). It's
either that or return an entire html page with fresh contents on the
page called by '/buildshelf/' + this.value "
Ya, I am not doing an ajax call because it is not really needed. I can possibly have new equipment and that would require more maintenance to tell the ajax call where to go for that piece of eqpt. The way I am doing would just require an array entry and a controller action. Anyway, I got it to work by doing this in the view: