Noob RJS Template Trouble

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/]

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/]

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

You Prob forgot to include your js files

Sent from my iPhone

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

  <%= javascript_include_tag :defaults %>

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

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

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