# Ajax

**URL:** <https://www.ruby-forum.com/t/ajax/183637>\
**Category:** Rails\
**Created:** [February 17, 2010, 7:41pm UTC](https://www.ruby-forum.com/t/ajax/183637 "2010-02-17T19:41:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [February 17, 2010, 7:41pm UTC](https://www.ruby-forum.com/t/ajax/183637/1 "2010-02-17T19:41:58Z")

</div>

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???

---

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [February 18, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/ajax/183637/2 "2010-02-18T16:52:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [February 18, 2010, 6:04pm UTC](https://www.ruby-forum.com/t/ajax/183637/3 "2010-02-18T18:04:41Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [February 18, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/ajax/183637/4 "2010-02-18T18:19:04Z")

</div>

On 17 February 2010 18:41, Manish B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![manish\_belsare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@manish\_belsare](https://www.ruby-forum.com/u/manish_belsare)\
**Post date:** [February 18, 2010, 7:56pm UTC](https://www.ruby-forum.com/t/ajax/183637/5 "2010-02-18T19:56:42Z")

</div>

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?
