Forum: Ruby on Rails Noob RJS Template Trouble

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Colin S. (Guest)
on 2009-01-29 20:37
(Received via mailing list)

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 at 2009-01-29 10:23:13)
  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/]

Processing JavaController#index (for at 2009-01-29 10:23:19)
  Session ID:
"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/]

headers in Firebug were:
Connection  close
Date  Thu, 29 Jan 2009 18:23:19 GMT
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!"?

Julian L. (Guest)
on 2009-01-29 21:34
(Received via mailing list)
You Prob forgot to include your js files

Sent from my iPhone
Colin S. (Guest)
on 2009-01-30 00:02
(Received via mailing list)
In my app/views/layouts/application.rhtml:

      <%= javascript_include_tag :defaults %>
Bill W. (Guest)
on 2009-01-30 00:19
(Received via mailing list)
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*
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
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 =>

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

Colin S. (Guest)
on 2009-01-30 00:23
(Received via mailing list)
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

Bill W. (Guest)
on 2009-01-30 00:39
(Received via mailing list)
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

Best regards,
This topic is locked and can not be replied to.