Forum: Ruby on Rails RJS

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.
RJS
Hamza K. (Guest)
on 2006-04-11 17:41
I am trying to use RJS as shown in this tutorial :

http://www.codyfauser.com/articles/2005/11/20/rail...

However it does not seem to work.  I am not getting any excpetions in
the logs. Here is what the logs say :

Parameters: {"action"=>"add", "controller"=>"homepage"}
Rendering homepage/add

The homepage/add is named add.rjs

I know that this file is being accessed, if I put some incorrect code
there it complains in the logs.

I am not sure that "rake rails:update" (in the application folder) works
correctly for me.  This is because I have updated to the latest version
of rails and then I copied conf/boot.rb to /tmp folder and did this
command

rake rails:update:configs

According to this post

http://weblog.rubyonrails.org/articles/2006/04/09/...

It should update your boot.rb.  But I did a diff and the files are the
same. This could mean that I have not got the correct js files to allow
RJS to work?  Is there a way of checking if I have the correect JS files
that support RJS ?

Here is ths code :

homepage/add.rjs :

page.replace_html 'header','RJS Template Test Complete!'

in homepage/list
<h1 id='header'>RJS Template Test</h1>
    <%= link_to_remote("Change Title", :url =>{ :action => 'add' }) %>

in the homepage controller

def add
end

By the way I am importing the javascripts like this :

<%= javascript_include_tag :defaults %>


I would appreciate any help, as I have been struggling all morning.

Thanks in advance.

Hamza
Kevin O. (Guest)
on 2006-04-11 19:56
(Received via mailing list)
try adding a :complete=>'alert(response.responseText)' to your function
call.

This should pop up the RJS output and give you more information about
why the call failed.

On Tuesday, April 11, 2006, at 3:41 PM, Hamza Khan-Cheema wrote:
>The homepage/add is named add.rjs
>
>Here is ths code :
>
>Thanks in advance.
>
>Hamza
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


_Kevin
Hamza K. (Guest)
on 2006-04-11 21:01
Keven,

Thanks fo the reply.  I have added an alert to the link.  This is what
it is now:

<%= link_to_remote("Change Title", :url =>{:action => :add }, :complete
=> "alert(request.responseText)") %>

I do get an alert.  This is what it says :

Element.update("header","RJS Template Test Complete!"); Load Suite
dispatch etc.

It still does not update the title (with a id of 'header'). But it does
seem to be actioning the correct code.  Does anyone have any suggestions
?

I even tried to put a doctype for the page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> etc.

I have also tried 'page.remove' and 'page.insert_html'  But nothing
seems to work.

Thanks.

Hamza


Kevin O. wrote:
> try adding a :complete=>'alert(response.responseText)' to your function
> call.
>
> This should pop up the RJS output and give you more information about
> why the call failed.
>
> On Tuesday, April 11, 2006, at 3:41 PM, Hamza Khan-Cheema wrote:
>>The homepage/add is named add.rjs
>>
>>Here is ths code :
>>
>>Thanks in advance.
>>
>>Hamza
>>
>>--
>>Posted via http://www.ruby-forum.com/.
>>_______________________________________________
>>Rails mailing list
>>removed_email_address@domain.invalid
>>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
> _Kevin
H. Wade M. (Guest)
on 2006-04-11 21:16
(Received via mailing list)
On Tue, 11 Apr 2006, Hamza Khan-Cheema wrote:

> Element.update("header","RJS Template Test Complete!"); Load Suite
> dispatch etc.
>
> It still does not update the title (with a id of 'header'). But it does
> seem to be actioning the correct code.  Does anyone have any suggestions
> ?

I had a similar problem when I was setting the Content-Type header to be
"text/html" for all actions.  RJS needs to be rendered with a different
Content-Type (application/javascript or something, can't remember right
now).  Check to see if you're doing something like that, maybe using a
:before_filter or similar thing to set it - when I did it, it was giving
the exact same symptoms you're describing.

--Wade
Hamza K. (Guest)
on 2006-04-11 21:52
Wade,

I am not seting the content type to HTML by default.  However I did have
the following in the file :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

I took this out but it had no effect.  I have also added this to the add
method :

def add
  @headers["Content-Type"] = "text/javascript"
end

But all this has no effect.  However what I am doing is, I am using UTF
characaters.  I am not sure this would effect anything ?

I will try and create an empty rails app to see if I am getting the same
error.   Other then that I am still stuck.

By the way, Is that add method correct ?  Can i change the header like
that when making a RJS request ?

Thanks

Hamza

H. Wade M. wrote:
> On Tue, 11 Apr 2006, Hamza Khan-Cheema wrote:
>
>> Element.update("header","RJS Template Test Complete!"); Load Suite
>> dispatch etc.
>>
>> It still does not update the title (with a id of 'header'). But it does
>> seem to be actioning the correct code.  Does anyone have any suggestions
>> ?
>
> I had a similar problem when I was setting the Content-Type header to be
> "text/html" for all actions.  RJS needs to be rendered with a different
> Content-Type (application/javascript or something, can't remember right
> now).  Check to see if you're doing something like that, maybe using a
> :before_filter or similar thing to set it - when I did it, it was giving
> the exact same symptoms you're describing.
>
> --Wade
Mats L. (Guest)
on 2006-04-12 11:16
(Received via mailing list)
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Cody F. (Guest)
on 2006-04-12 18:29
(Received via mailing list)
Hamza,

What version is your Prototype library?  Take a look inside
public/javascripts/prototype.js to find out.

On 4/11/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
> Element.update("header","RJS Template Test Complete!"); Load Suite
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> etc.
> > try adding a :complete=>'alert(response.responseText)' to your function
> >>Thanks in advance.
> >
> > _Kevin
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody F.
http://www.codyfauser.com
Hamza K. (Guest)
on 2006-04-12 19:34
Cody,

The version of my Prototype js is : 1.5.0_rc0

Is this the correct version ?

Thanks

Hamza

Cody F. wrote:
> Hamza,
>
> What version is your Prototype library?  Take a look inside
> public/javascripts/prototype.js to find out.
>
> On 4/11/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
>> Element.update("header","RJS Template Test Complete!"); Load Suite
>> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> etc.
>> > try adding a :complete=>'alert(response.responseText)' to your function
>> >>Thanks in advance.
>> >
>> > _Kevin
>>
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> Rails mailing list
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Cody F.
> http://www.codyfauser.com
Cody F. (Guest)
on 2006-04-12 20:44
(Received via mailing list)
Yeah, that is correct.  Try making your rjs template only this:
page.alert('test') and see if you get a popup.

On 4/12/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
> Cody F. wrote:
> >> >
> >
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody F.
http://www.codyfauser.com
Rizwan R. (Guest)
on 2006-04-13 07:47
(Received via mailing list)
Needless to say but a precaution; when you make rjs template for an
action,
be sure you don't have any other template view (rhtml or rxml) for the
same
action.
Hamza K. (Guest)
on 2006-04-13 14:46
Cody,

Even that does not display an alert box.  I have tried multiple things
in the add.rjs file

Rizwan,

I do not have any other view named add.

Hamza

Cody F. wrote:
> Yeah, that is correct.  Try making your rjs template only this:
> page.alert('test') and see if you get a popup.
>
> On 4/12/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
>> Cody F. wrote:
>> >> >
>> >
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Cody F.
> http://www.codyfauser.com
Cody F. (Guest)
on 2006-04-14 07:56
(Received via mailing list)
Can you post the source from your browser and your controller code?

On 4/13/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
>
> >>
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody F.
http://www.codyfauser.com
Hamza K. (Guest)
on 2006-04-28 20:05
Hi,

I have finaly figured out why RJS was not working :)  My rails setup was
going through Apache2 using fastcgi.  I went through this tutorial :

http://fo64.com/articles/2005/10/20/rails-on-breezy

However, when I turned off Apache and went through WEBrick AJAX started
to worked :). This obvsioully meant that Apache was not sending the AJAX
requsts to Rails.

Thank you to everyone who helped. I just need to figure out how to get
Apache working now :)

Hamza


Cody F. wrote:
> Can you post the source from your browser and your controller code?
>
> On 4/13/06, Hamza Khan-Cheema <removed_email_address@domain.invalid> wrote:
>>
>> >>
>> Rails mailing list
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>
>
> --
> Cody F.
> http://www.codyfauser.com
This topic is locked and can not be replied to.