How to ajaxify?

Hi all.

I’m doing my own blog-like site, so I’ve an Post controller and an
Comments
controller and I want to ajaxify my comments form. So, I’ve did the
following:

[comments_controller.rb]
class CommentsController < ResourceController::Base
belongs_to :post, :article, :photo

create do
flash “Comment posted successfuly”
wants.html { redirect_to :back }
wants.js { render :layout => false }
end
end
[/comments_controller.rb]

[create.js.rjs]
page.replace_html(“comments”, :partial => “comment”, :collection =>
@post.comments)
[/create.js.rjs]

[views/posts/show.html.erb]
<%= render :partial => “post”, :object => @post %>

Comments

<%= render :partial => "comments/comment", :collection => @post.comments %>

<% remote_form_for([@post,Comment.new], :update => “new_comment”) do |f|
%>
<%= render :partial => “comments/form”, :locals => { :f => f } %>

<%= submit_tag "Create" %>

<% end %> [/views/posts/show.html.erb]

Please, also note that I’m using resource_controller plugin.

When I write down my comment, comments_partial is updated and my new
comment
appears, but I also got the following:

[output]
Element.update(“comments”, “\u003Ca
href="http://presto.stellar.com.br"\u003Edavi\u003C/a\u003E said, in
Post
Fouth post at\nSun Jun 15 12:04:33 -0300
2008:\u003Cbr/\u003E\nCommenting!
I’m enjoying Rails!!! Finaly!! =D\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca
href="http://presto.stellar.com.br"\u003Edavi\u003C/a\u003E said, in
Post
Fouth post at\nSun Jun 15 12:05:25 -0300 2008:\u003Cbr/\u003E\nI’ve
learned
how to restart Passenger… =)\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca
href="http://my.coolsite.com"\u003Eauthor\u003C/a\u003E said, in Post
Fouth
post at\nMon Jun 16 00:50:43 -0300 2008:\u003Cbr/\u003E\nmy
comment\n\u003Cbr/\u003E\u003Cbr/\u003E”);
[/output]

and my comments’ form desapair.

What am I missing here?

Please, sorry for my very bad English.

Best regards,

Davi V.

E-mail: [email protected]
MSN : [email protected]
GTalk : [email protected]
Skype : davi vidal
YIM : davi_vidal
ICQ : 138815296

On Jun 16, 4:56 am, Davi V. [email protected] wrote:

comment\n\u003Cbr/\u003E\u003Cbr/\u003E");
[/output]

Is that what is inserted into your comments div? The thing here is
that ajax in rails can be used in one of two ways. The first is that
you give remote_form_for, link_to_remote etc… a dom id via
the :update option and then response from your action replaces the
contents of that page element. In this case you action should just
render an html fragment. The second way is your action renders
javascript, and the javascript on the page executes it when it comes
back (rjs is one way of generating javascript. Here you’re mixing the
two: you’re specifying :update but then you’re rendering rjs. Pick one
or the other.

Fred

Em Monday 16 June 2008, Frederick C. escreveu:

=)\n\u003Cbr/\u003E\u003Cbr/\u003E\u003Ca
href="http://my.coolsite.com"\u003Eauthor\u003C/a\u003E said, in Post
Fouth post at\nMon Jun 16 00:50:43 -0300 2008:\u003Cbr/\u003E\nmy
comment\n\u003Cbr/\u003E\u003Cbr/\u003E");
[/output]

Is that what is inserted into your comments div?

Yes.

The thing here is that ajax in rails can be used in one of two ways.
The first is that you give remote_form_for, link_to_remote etc…
a dom id via the :update option and then response from your action
replaces the contents of that page element. In this case you action
should just render an html fragment. The second way is your action
renders javascript, and the javascript on the page executes it when
it comes back (rjs is one way of generating javascript. Here you’re
mixing the two: you’re specifying :update but then you’re rendering
rjs. Pick one or the other.

I’ve droped down :update and all is working fine now.

Thank you very much, Fred.


Davi V.

E-mail: [email protected]
MSN : [email protected]
GTalk : [email protected]
Skype : davi vidal
YIM : davi_vidal
ICQ : 138815296