# Requesting help on Ajax link\_to\_remote RJS error

**URL:** <https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476>\
**Category:** Rails\
**Created:** [March 31, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476 "2008-03-31T23:02:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newtoruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@newtoruby](https://www.ruby-forum.com/u/newtoruby)\
**Post date:** [March 31, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476/1 "2008-03-31T23:02:46Z")

</div>

I am trying to make a remote call to an action when I click a link on  
one page.

I have ‘books’ and ‘haves’ models. I have ‘my\_controller’ . In the  
index.rhtml I have a link ‘Add a book’. I am trying to replace the  
add\_form in the same div where the list of books has been shown. When  
I click the link my form is showing twice along with some try catch  
blocks saying an RJS error. However I am not having any RJS involved  
in it.

Could somebody help me to resolve my problem.

Any help is very appreciated, and thanks in advance.

my index.rhtml code is

=============================================================  
\<%= javascript\_include\_tag :defaults %\>

# Books I Have

### \<%= link\_to\_remote 'Add a book', :update =\>'newhavediv', :url =\>{:action =\>'new\_own'} %\>

=============================================================
# My controller code in action ‘new\_own’

# def new\_own @new\_book = Book.new render :update do |page| page.replace\_html “newhavediv”, :partial =\> “new\_own” end end

# my new\_own.rhtml code is

\<%= javascript\_include\_tag :defaults %\>  
\<% form\_remote\_tag( :url =\> { :action =\> ‘create’},:update  
=\>‘newhavediv’) do |form| %\>

```
            <p><label for="book_title" class="left"> Book Title</

```

label\>  
\<%= text\_field ‘newbook’, ‘title’ %\>

```
            <p><label for="book_author" class="left"> Author</

```

label\>  
\<%= text\_field ‘newbook’, ‘author’ %\>

  
\<%= submit\_to\_remote “Submit”, :url =\>{ :action  
=\>‘create’}, :update =\>‘newhavediv’ %\>
# \<% end %\>

# I am getting the following error when I click on the ‘Add a book’ link. The form and textfields but it is not showing the submit button.

try { Element.update(“newhavediv”, "  
\n  
Add a New text book to your Have List  
\n\n\n\n\n\n  
\n\n

Book Title\n \*  
\n\n

Author\n \*  
\n\n

Edition\n  
\n\n

ISBN Number\n  
\n\n

Book Condition\n  
\n\n\n\n \n

\n\n\n\n\n  
\n\n  
"); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert('Element.update(“newhavediv”, "  
\n  
Add a New text book to your Have List  
\n\n\n\n\n\n  
\n\n

# Book Title\n \* \n\n

Author\n \*  
\n\n

Edition\n  
\n\n

ISBN Number\n  
\n\n

Book Condition\n  
\n\n\n\n \n

\n\n\n\n\n  
\n\n  
");’); throw e }

---

<div class="post-metadata">

**Author:** ![newtoruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@newtoruby](https://www.ruby-forum.com/u/newtoruby)\
**Post date:** [March 31, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476/2 "2008-03-31T23:23:30Z")

</div>

On 31 Mar 2008, at 22:01, newToruby wrote:

> I am trying to make a remote call to an action when I click a link on  
> one page.
> 
> I have ‘books’ and ‘haves’ models. I have ‘my\_controller’ . In the  
> index.rhtml I have a link ‘Add a book’. I am trying to replace the  
> add\_form in the same div where the list of books has been shown. When  
> I click the link my form is showing twice along with some try catch  
> blocks saying an RJS error. However I am not having any RJS involved  
> in it.

Well you do have some rjs right in the render :update block. You  
should both pass :update to link\_to\_remote and use render :update.  
It looks like your new\_own action could just be render :partial =\>  
‘new\_own’

Fred

---

<div class="post-metadata">

**Author:** ![newtoruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@newtoruby](https://www.ruby-forum.com/u/newtoruby)\
**Post date:** [April 1, 2008, 3:40am UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476/3 "2008-04-01T03:40:47Z")

</div>

On Mar 31, 2:22 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I click the link my form is showing twice along with some try catch  
> > blocks saying an RJS error. However I am not having any RJS involved  
> > in it.
> 
> Well you do have some rjs right in the render :update block. You  
> should both pass :update to link\_to\_remote and use render :update.  
> It looks like your new\_own action could just be render :partial =\>  
> ‘new\_own’
> 
> Fred

Thanks! Fred

But I don’t have any rjs code in :update block. I am passing :update  
to link\_to\_remote and using render :update. I am new to Ajax though I  
have done rails and ruby programming before. Could you please  
elaborate more on what should be doing? ?As I understand, I am already  
doing what you suggested me. Or I am missing or my bad.

Thanks

---

<div class="post-metadata">

**Author:** ![newtoruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@newtoruby](https://www.ruby-forum.com/u/newtoruby)\
**Post date:** [April 2, 2008, 1:08am UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476/4 "2008-04-02T01:08:59Z")

</div>

Thank you very much. It is working now.

On Apr 1, 12:42 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![newtoruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@newtoruby](https://www.ruby-forum.com/u/newtoruby)\
**Post date:** [April 1, 2008, 9:43am UTC](https://www.ruby-forum.com/t/requesting-help-on-ajax-link-to-remote-rjs-error/133476/5 "2008-04-01T09:43:26Z")

</div>

> But I don’t have any rjs code in :update block. I am passing :update  
> to link\_to\_remote and using render :update. I am new to Ajax though I  
> have done rails and ruby programming before. Could you please  
> elaborate more on what should be doing? ?As I understand, I am already  
> doing what you suggested me. Or I am missing or my bad.

Oops, I meant ‘You shouldn’t both pass :update to link\_to\_remote and  
use render :update’, quick slip of the keyboard there. And you do have  
rjs in your :update block (what do you think page.replace\_html etc…  
is ?). Like I said if your action just renderered your partial it  
would probably be ok (although if you are expected render :partial =\>  
‘new\_own’ to render new\_own.rhtml, it won’t. It will render  
\_new\_own.rhtml)

Fred
