RJS in action vs .js file (page object)


Would anyone be able to suggest why the following works in the action
but not when placed in a .js file, called by the action?

It's the page << "$('basket_popup').popup.show();" line I'm interested

def show

    respond_to do |format|
      format.js do
        render :showbasket do |page|
          page << "$('basket_popup').popup.show();"


However when I have show.js and remove the block from format.js it
fails. I get a javascript error on the page along the lines of popup
has no properties/attributes?


page << "$('basket_popup').popup.show();"

I'm sure it's a simple one but I can't see it??

Name your file show.js.rjs so Rails knows to use the RJS renderer to render it into the page. Might be as simple as that.

Best regards

Peter De Berdt