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 }