Rjs


#1

I am trying to use RJS as shown in this tutorial :

http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates

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/rails-1-1-2-tiny-fix-for-gems-dependenciesI

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

RJS Template Test

<%= 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


#2

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


#3

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.

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


#4

Wade,

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

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


#5

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


#6

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#7

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

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


#8

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


#9

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.


#10

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

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


#11

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


#12

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


#13

Hi,

I have finaly figured out why RJS was not working :slight_smile: 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 :slight_smile:

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