Forum: Ruby on Rails Noob RJS Template Trouble

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
59d2de0dc2028141540521eb2360c40a?d=identicon&s=25 Colin Summers (Guest)
on 2009-01-29 19:37
(Received via mailing list)
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
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-01-29 20:34
(Received via mailing list)
You Prob forgot to include your js files

Sent from my iPhone
59d2de0dc2028141540521eb2360c40a?d=identicon&s=25 Colin Summers (Guest)
on 2009-01-29 23:02
(Received via mailing list)
In my app/views/layouts/application.rhtml:

      <%= javascript_include_tag :defaults %>
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2009-01-29 23:19
(Received via mailing list)
Hi Colin,

Colin Summers 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
59d2de0dc2028141540521eb2360c40a?d=identicon&s=25 Colin Summers (Guest)
on 2009-01-29 23: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
not.

--Colin
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2009-01-29 23:39
(Received via mailing list)
Hi Colin,

Colin Summers 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
This topic is locked and can not be replied to.