# Noob RJS Template Trouble

**URL:** <https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957>\
**Category:** Rails\
**Created:** [January 29, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957 "2009-01-29T19:37:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/1 "2009-01-29T19:37:48Z")

</div>

Hello,

I am certain this is a simple thing. The crazy thing is that last  
summer I created my first Rails application with some .rjs templates  
and that still works. But making a new one recently I have become  
totally stumped. I thought it was something complicated I was doing  
(update the DOM, insert some HTML…) so I backed way off, created a  
test application and just tried to do Hello, World. No joy.

MacOS, latest. Rails 2.1.2.

Fire up Mongrel on post 3000. It loads the index.rhtml file just file.  
Shows me the link which is coded like this:

link\_to\_remote(“Say hello”,{:action =\> ‘hello’})

then hello.rjs is just  
page.alert “Hello!”

Okay, I’m missing the “world” part.

I load the first page and then click on the link. The log says:  
Processing JavaController#index (for 127.0.0.1 at 2009-01-29 10:23:13)  
[GET]  
Session ID: dee44c8f4a7b2ded8b35130b173b5c37  
Parameters: {“action”=\>:index, “controller”=\>“java”}  
Rendering template within layouts/application  
Rendering java/index  
Completed in 0.07462 (13 reqs/sec) | Rendering: 0.07254 (97%) | DB:  
0.00000 (0%) | 200 OK [[http://localhost/](http://localhost/)]

Processing JavaController#index (for 127.0.0.1 at 2009-01-29 10:23:19)  
[POST]  
Session ID:  
BAh7BzoMY3NyZl9pZCIlZjA1NjRjOTZjZTBmNTBmMmQwYjFhN2U1ZmIyYTM0  
OWQiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh  
c2h7AAY6CkB1c2VkewA=–0338e780c3835ee34ea7c407d42824deb09880b7  
Parameters:  
{“authenticity\_token”=\>“a59d4b5adc4b75d2b1573e23569e157c8f6471f9”,  
“action”=\>:index, “controller”=\>“java”}  
Rendering java/index  
Completed in 0.00281 (356 reqs/sec) | Rendering: 0.00070 (24%) | DB:  
0.00000 (0%) | 200 OK [[http://localhost/](http://localhost/)]

headers in Firebug were:  
Connection close  
Date Thu, 29 Jan 2009 18:23:19 GMT  
Set-Cookie  
\_test\_session=BAh7ByIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo  
%0ASGFzaHsABjoKQHVzZWR7ADoMY3NyZl9pZCIlZjA1NjRjOTZjZTBmNTBmMmQw  
%0AYjFhN2U1ZmIyYTM0OWQ%3D–f06ff17de7891930dbb01ebce2bc90d476b9d9d6;  
path=/  
Status 200 OK  
X-Runtime 0.00281  
Etag “25d3a7f2cfd3bfe151df328b04ff9b0e”  
Cache-Control private, max-age=0, must-revalidate  
Server Mongrel 1.1.5  
Content-Type text/html; charset=utf-8  
Content-Length 390

What else should I post to help someone clue me in here? Why don’t I  
get the little sheet-dialog dropping down in the browser window  
saying, “Hello!”?

Thanks,  
–Colin

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 8:34pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/2 "2009-01-29T20:34:04Z")

</div>

You Prob forgot to include your js files

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 11:02pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/3 "2009-01-29T23:02:03Z")

</div>

In my app/views/layouts/application.rhtml:

```
  <%= javascript_include_tag :defaults %>
```

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/4 "2009-01-29T23:19:20Z")

</div>

Hi Colin,

Colin S. wrote:

> I load the first page and then click on the link. The log says:  
> Processing JavaController#index

The action that you _intend_ to be invoked by your link is ‘hello’.  
According to the log you posted, clicking the link is _actually_  
invoking  
the ‘index’ action instead. The problem may lie in your coding of the  
link\_to\_remote. Check the page source of your ‘index’ view. It should  
have  
an Ajax call to ‘java/hello’. If it doesn’t, try changing your  
link\_to\_remote to:

link\_to\_remote(“Say hello”, :url =\>{:action =\> ‘hello’})

or even more readably…

link\_to\_remote(“Say hello”, :url =\>{:controller =\> ‘java’, :action =\>  
‘hello’})

If you’re page source already contains the Ajax request to ‘java/hello’,  
then the problem’s in your routes.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/5 "2009-01-29T23:23:00Z")

</div>

Thanks Bill!

That worked. I had

\<%= link\_to\_remote(“Say hello”,{:action =\> ‘hello’}) %\>

and changed it to:

\<%= link\_to\_remote(“Say hello”, :url =\>{:controller =\>  
‘java’, :action =\> ‘hello’}) %\>

And now it works. That’s mysterious to me. I thought the controller  
would be constant on a page served by that controller, but I guess  
not.

–Colin

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [January 29, 2009, 11:39pm UTC](https://www.ruby-forum.com/t/noob-rjs-template-trouble/158957/6 "2009-01-29T23:39:03Z")

</div>

Hi Colin,

Colin S. wrote:

> Thanks Bill!

You’re welcome.

> would be constant on a page served by that controller, but I guess  
> not.

The problem was probably the lack of the ‘:url =\>’.

The default controller for a view is, indeed, its ‘own’ controller. I  
recommended the addition of the ‘:controller’ component just for  
readability; the link\_to\_remote can point to any controller. The code  
should still work fine if you take the controller pair out of the url  
hash.

Best regards,  
Bill
