Requesting help on Ajax link_to_remote RJS error

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 }

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

On Mar 31, 2:22 pm, Frederick C. [email protected]
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

Thank you very much. It is working now.

On Apr 1, 12:42 am, Frederick C. [email protected]

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs