# RJS in action vs .js file (page object)

**URL:** <https://www.ruby-forum.com/t/rjs-in-action-vs-js-file-page-object/140572>\
**Category:** Rails\
**Created:** [June 16, 2008, 11:57am UTC](https://www.ruby-forum.com/t/rjs-in-action-vs-js-file-page-object/140572 "2008-06-16T11:57:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [June 16, 2008, 11:57am UTC](https://www.ruby-forum.com/t/rjs-in-action-vs-js-file-page-object/140572/1 "2008-06-16T11:57:55Z")

</div>

Hi,

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  
in.

def show

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

```

end

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?

-show.js-

page \<\< “$(‘basket\_popup’).popup.show();”

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

---

<div class="post-metadata">

**Author:** ![reynar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@reynar](https://www.ruby-forum.com/u/reynar)\
**Post date:** [June 16, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/rjs-in-action-vs-js-file-page-object/140572/2 "2008-06-16T12:19:47Z")

</div>

On 16 Jun 2008, at 11:57, Andrew E. wrote:

> -show.js-
> 
> 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
