This link updates a div called selected_product. On the page that is
rendered in the updated div, I use a Greybox plugin to show images, but
when the div is updated, the Greybox is disabled for some reason. I
found this site which seemed to fix my problem temporarily.
The page that you're showing alludes to the fact that it is an
incomplete example. The comment that they've included in the
render :update block (update the page dynamically) is not a statement
indicating what happens as a result of executing the block -- it's a
direction to you to do the work.
In the 'big picture', you're using two overlapping methods to update
the div. Using the :update parameter on link_to_remote causes the
framework to generate an Ajax.Updater call that expects an html
response; the Updater will take the contents of the response and paste
them into the dom element you specify. If you use this approach
then your format.js actually needs to render the _html_ that the
Ajax.Updater needs to update the 'selected_product' div.
The 'render :update' call on the server attempts to do something very
similar. It assumes that you've made a request for javascript and
provides a number of convenience methods for writing that javascript
response. (It's the same thing as RJS, if you're read about that).
If you use this approach you need to have your action use something
like
Unfortunately, the two methods cannot be used together. (If you think
about it, this makes sense... you're sending a request that expects
html and sending a response in javascript). The javascript error that
you're seeing -- the empty js try-catch -- is the default
implementation of render(:update) with nothing added. If you're only
updating one element on the page (as it sounds you are) then you're
better off keeping the :update parameter and changing your format.js
to render the html that it expects. If you need to update the page in
more than one place then drop the :update parameter and write all the
update in the render(:update) block. In the latter case you are
actually better off writing an rjs file to promote better separation
in your code (e.g., show.js.rjs). Rjs files need only contain the
'guts' of the js response; they are automatically wrapped in the
render(:update) block for you.
Andy, I truly appreciate your quick reply and help but well I'm still a
noob so comprehending everything might be a little too much. I do want
to stick with the :update parameter but don't quite understand what you
meant by changing the "format.js to render the html". Could you please
elaborate.