Rails 2.0.2 + RJS


I had ajax commenting on my app, which worked perfectly on Rails
v1.2.6, but does not work the same in Rails 2.02. Basically the
comment gets added, but the visual effects do not work (ie lines 2 + 3
of create.rjs)

page.insert_html :bottom, ‘comments’, :partial => ‘comment’
page.visual_effect :appear, “comment_#{@comment.id}”
page.visual_effect :highlight, “comment_#{@comment.id}”, {:startcolor
=> ‘"#84E003"’}

def create
@comment = Comment.new(params[:comment])
@comment.user = User.find(current_user)
@comment.story = Story.find(params[:story_id])
respond_to do |format|
if @comment.save
format.html { redirect_to story_url(@comment.story) }
format.html { redirect_to story_url(@comment.story) }

I have tried changing to create.js.rjs, but that makes no difference?

Doe anyone have any experience with this in Rails 2.0.2?


Elaborate on “do not work”

Do they get called and raise an error do they not get called at all? Is
page loading at all? Are you using Firefox? Do you have Firebug? What is
Firebug telling you about the AJAX request? Do you like cheese on toast?
What’s the square root of 24… the questions are endless.

On Jan 23, 2008 12:07 PM, PJAY79 [email protected] wrote:

page.visual_effect :appear, "comment_#{@comment.idcomment_#[email protected]
respond_to do |format|

Doe anyone have any experience with this in Rails 2.0.2?


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Hi Ryan

There are no errors thrown in the console or in Firefox. The comment
is added, but without the visual effects, as i said… so i guess
they do not get called at all…

I will have to install Firebug!

It just seems odd to me as it was working perfect on Rails 1.2.6.


Ok i installed Firebug.

I looked in ‘console > response’

This is what appears…

try {

new Insertion.Bottom(“comments”, "\u003Cdiv id=“comment_52” class=

“praveen”\u003Cbr /\u003E\n\n\u003Cimg alt=“Imgp1090_thumb” id=
“avatar_thumb” src="/avatars/0000

/0001/IMGP1090_thumb.JPG?1200983769" /\u003E\n\n\u003Ca href="/users/

from Australia said this on January 23, 2008 16:48.\u003C/p\u003E\n\n
\u003Ca href="#" onclick="if

(confirm(‘Are you sure?’)) { new Ajax.Request(’/comments/52?
story_id=4’, {asynchronous:true, evalScripts

:true, method:‘delete’}); }; return false;"\u003EDESTROY\u003C/a\u003E

new Effect.Appear(“comment_52”,{});

new Effect.Highlight(“comment_52”,{startcolor:’"#84E003"’});

} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert('new
Insertion.Bottom(“comments”, "\u003Cdiv

id=\“comment_52\” class=\“comment\”\u003E\n\u003Cp\u003E\
“praveen\”\u003Cbr /\u003E

\n\n\u003Cimg alt=\“Imgp1090_thumb\” id=\“avatar_thumb\”

.JPG?1200983769\" /\u003E\n\n\u003Ca href=\"/users/1\"
\u003EPraveen\u003C/a\u003E from Australia

said this on January 23, 2008 16:48.\u003C/p\u003E\n\n\u003Ca
href=\"#\" onclick=\"if (confirm

(‘Are you sure?’)) { new Ajax.Request(’/comments/52?story_id=4’,
{asynchronous:true, evalScripts

:true, method:‘delete’}); }; return false;\"\u003EDESTROY\u003C/a

\n");\nnew Effect.Appear(“comment_52”,{});\nnew

#84E003"’});’); throw e }



Have you found a solution to this. I am having the same problem.

I do something like this:

        page.replace "student_#{@student.id}", :partial =>

“show”, :locals => {:rendition => @rendition}
page.visual_effect :highlight, “student_#{@student.id}”,
{:endcolor => “’#EAE8D5’”, :endcolor => “’#EAE8D5’”}

If I comment out the 2nd line the replace works fine. The highlight
seems to kill any kind of javascript running.


I’ve seen this type of problem a lot on doing a google search…and on
this list…

“alert(‘RJS error:\n\n’ + e.toString())”

But everyone seems to have different ideas as to what is the problem
and some solutions work for some and not for others…

Nothing i’ve tried works…



I just did a refresher on rjs for rails 2

I wrote up what I changes. I was using Peepcode rjs screencast
my post


john i

Hi there

Thanks for tips.

I tried these changes and i can get various effects to work eg
blind_down, slide_down, pulsate, fade, shake…

However the HIGHLIGHT effect does not seem to work, and it does not
throw up any errors in the console either!

What am i doing wrong with this? Is there a different way to code

Thanks for the help…:slight_smile:


I think you should have a create.html.erb file incase the user does
not have javascript turned on.

In the controller you have the respond_to

respond_to do |format|
format.js #create.js.rjs
format.html #create.html.erb

or a more detailed version . . .

respond_to do |format|
if @task.save
format.html do
flash[:notice] = ‘Task was successfully created.’
redirect_to{ (@task)
format.html { render :action => “new” }
format.js { render :template => “shared/error.js.rjs” }

john i

For my Highlighting I am using this code

(in the js.rjs file)
page.insert_html :bottom, ‘tasks’, :partial => @task # adds new
task into the partial
page[‘task_form’].reset #
resets the form
page.visual_effect :highlight, “task_#{@task.id}”, #
highlights the just added div that has the new task
:startcolor => ‘#336699

I use a partial in my index.html.erb view.

<%= render :partial => @tasks %>

_task.html.erb file
<% div_for task do %>
<%= h(task.name) %>
<% end %>

the div_for task do gives the div an id = to task_1 (or what ever the
id of the task is.)
I have one task that has an id of 1
I add a new task. It gets an id of 2

In the rjs

  1. It adds a new div, with an id = task_2, into the div on the index
    view that has the id of “tasks”.
  2. It clears the form with the reset.
  3. highlight the task_2

my form view

<% remote_form_for(:task, :url => tasks_path, :html => {:id =>
“task_form”}) do |f| %>

<%= f.text_field :name %>

<%= f.text_field :value %>

<%= f.submit "Create" %>

<% end %>


I’m having the same problems, except I can’t even seem to get any of
the effects to work or calls like ‘page.call :my_function’. I’ve got
an index.html.erb file, and an index.hs.rjs file. The js.rjs file just

page.visual_effect :highlight, “my_div”

and my controller has:

respond_to do |format|
format.js { render :template => “index.js.rjs” }

But whatever I do I can’t seem to make this work. It always complains
with the try/catch error that has something like “alert(‘RJS error:\n
\n’ + e.toString())”. I’ve also tried changing the page.visual_effect
to a page.call, and I cant make this work either. Any ideas?

Why the hell did this change in rails 2.0 anyway, what was wrong with
the way it worked, where you could just do:

render :update do |page|
page.call :alert, “Im js”

And not have to worry about creating a stupid js.rjs file.