Ajax

Sir can u guide me in implementation of Ajax calls in Ruby and Rails?
wen i m implementing a new page it gives th following op:

“try {
Element.hide(“add_answer_link_for_post_-613772418”);
Element.update(“new_answer_form_for_post_-613772418”, “<form
action=”/answers” method=“post” onsubmit=“new
Ajax.Request(’/answers’, {asynchronous:true, evalScripts:true,
parameters:Form.serialize(this)}); return false;”>\n\n

New Answer\n \n \n\n\n\n"); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.hide(\"add_answer_link_for_post_-613772418\");\nElement.update(\"new_answer_form_for_post_-613772418\", \"\\n\\n New Answer\\n \\n \\n\\n\\n\\n\");'); throw e }"

I want to eliminate this problem wen i m implementing ajax requests…
Please help…

ALso m unable to understand the follwing code:

<%= render :partial => "comments/comment", :collection => post.comments %>
<% if logged_in? %>
<%= link_to_remote "Add a comment", :url => new_comment_path(post.blog, post), :method => :get %>
<% end %>

def new
@comment = Comment.new
respond_to do |format|
format.js do
render :update do |page|
page.hide “add_comment_link_for_post_#{@post.id}”
page.replace_html “new_comment_form_for_post_#{@post.id}”,
:partial => “new”
end
end
end
end

please can anyone guide me wat does
“add_comment_ink_for_post_#{@post.id}” do???

Hi Manish B.

<% if logged_in? %>

<%= link_to_remote "Add a comment", :url => new_comment_path(post.blog, post), :method => :get %>

please can anyone guide me wat does
“add_comment_ink_for_post_#{@post.id}” do???

From your view code add_comment_ink_for_post_#{@post.id} is some div 

For example of @post.id=2 Then that div will be
add_comment_ink_for_post_2

page.hide “add_comment_link_for_post_#{@post.id}”

What this does is hide a div element As an example it hides the div
add_comment_ink_for_post_2

Sijo

Sir,
Can u please help me in the problem that is present at the top??
I dont know why ruby isnt supporting AJAX calls???
wat should i do 2 eliminate the problem…It is urgent…!
Please help…

On 17 February 2010 18:41, Manish B. [email protected] wrote:

id="answer_ans_string" name="answer[ans_string]"
type=\"submit\" value=\"Create\"
/>\n\n\n\n");'); throw e }"

You say that you get this when you have implemented a new page, but
you have not shown the code of your page. It is therefore difficult
for anyone to suggest what is wrong.

Colin

def new
@answer = Answer.new
respond_to do |format|
format.js do
render :update do |page|
page.hide “add_answer_link_for_post_#{@post.id}”
page.replace_html “new_answer_form_for_post_#{@post.id}”,
:partial => “new”
end
end
end
end

_new.html.erb:
<% remote_form_for(:answer, :url => answers_path) do |form| %>

New Answer <%= form.text_area :body, :rows => 10, :cols => 40 %> <%= submit_tag "Create" %> <% end %>

def create
@answer = Answer.new(params[:answer])
@answer.user = User.find(session[:user_id])
@answer.post = @post
respond_to do |format|
if @answer.duplicate? or @post.answers << @answer
format.js do
render :update do |page|
page.replace_html “answers_for_post_#{@post.id}”,
:partial => “answers/answer”,
:collection => @post.answers
page.show “add_answer_link_for_post_#{@post.id}”
page.hide “new_answer_form_for_post_#{@post.id}”
end
end
else
format.js { render :nothing => true }
end
end
end

_answer.html.erb


<% if logged_in? and answer.authorized?(User.find(session[:user_id])) %> <%= link_to_remote "(delete)", :url => answer_path(answer.post.blog, answer.post, answer), :method => :delete, :confirm => 'Are you sure?' %> <% end %>

ABove is the code that uses Ajax but fails wen run…y?