Forum: Ruby on Rails Starting with RJS - not working

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.
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-14 11:43
(Received via mailing list)
Hi,
I'm trying to work with RJS and folowed Cody Fauser's tutorial
(http://www.codyfauser.com/articles/2005/11/20/rail...)
I've started by creating a new rails applications and executing
rake freeze_edge
rake rails:update:javascripts
rake rails:update:scripts

After that I've created a controller:
class DtestController < ApplicationController
  def add
  end
end

Created the files add.rhtml and add.rjs in views/dtest/ ,and
dtest.rhtml in views/layouts.
I've started my server and called my add action and nothing happends .
Can anyone explain me what I did wrong ?
My prototype version is 1.5.0_pre0

Thanks,
Ovidiu
1e90246fc67e699c32e59db89d4ff5c3?d=identicon&s=25 Michael Kaiser (Guest)
on 2006-03-14 12:05
(Received via mailing list)
Hi,

I didn't try RJS templates yet, but from what I understand if there are
both a .rhtml and a .rjs template, then rails picks up the .rhtml one.
Waht you'll want to do in your add action is change the view produced by
a _different_ action.

HTH,
Michael
D445ccdec864bfdc41e3d6333911387c?d=identicon&s=25 Eduardo Yáñez Parareda (Guest)
on 2006-03-14 12:14
(Received via mailing list)
>
> Created the files add.rhtml and add.rjs in views/dtest/ ,and
> dtest.rhtml in views/layouts.
>

The tutorial says:

Rails now looks for templates with an extension of .rjs, in addition to
.rhtml and .rxml, so create a view named add.rjs for your controller and
add
the following code to it: bla, bla....

It doesn't say anything about create a .rhtml view. It only says that
last
version of Rails search for templates .rjs too.
I haven't used RJS but I think you only need .rjs view to follow the
tutorial.
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-14 12:26
(Received via mailing list)
What I understand is that the .rjs page (which must have the same name
with the .rhtml page) is used  -- after -- the page is rendered

>From the tutorial>>>
Unlike conventional templates which are used to render the results of
an action, these templates generate instructions on how to modify an
already rendered page. This makes it easy to modify multiple elements
on your page in one declarative Ajax response. Actions with these
templates are called in the background with Ajax and make updates to
the page where the request originated from.

>>>

Ovidiu
1e90246fc67e699c32e59db89d4ff5c3?d=identicon&s=25 Michael Kaiser (Guest)
on 2006-03-14 12:32
(Received via mailing list)
Ovidiu EFTIMIE wrote:
> What I understand is that the .rjs page (which must have the same name
> with the .rhtml page) is used  -- after -- the page is rendered

No, it must not have the same name. There could potientially be several
actions wanting to change the rendered page in some way, so they have to
be distinct from the action that originally rendered the page. Give it a
try and make different actions for rendering and changing the page...
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-03-14 12:48
Ovidiu EFTIMIE wrote:
> What I understand is that the .rjs page (which must have the same name
> with the .rhtml page) is used  -- after -- the page is rendered

Nope, it works on an existing page.

so you call /controller/show/1, that triggers
views/controller/show.rhtml to display stuff.

You then issue an ajax call to /controller/add_list_item/1, that will
trigger /views/controller/add_to_list_item.rjs which returns javascript
to modify the existing (show) page.

Each action renders only one template, some are (r)html, some are (r)js.

Is this any clearer ?

A.
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-14 14:05
(Received via mailing list)
I've added an index action
class DtestController < ApplicationController
  def index
  end
  def add
  end
end
and renamed the add.rhtml to index.rhtml.
Now it works well.
 Acctually at the beggining id didn't work at all . I've deleted the
ruby session from %TEMP% and then is started to work

Thanx,
Ovidiu
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-14 14:17
(Received via mailing list)
Thanx Alan. Much clearer:)
This topic is locked and can not be replied to.