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 %> <div class ="havediv"> <div id = "newhavediv"> <div class="heading"> <h1>Books I Have </h1> <h3><%= link_to_remote ''Add a book'', :update =>''newhavediv'', :url =>{:action =>''new_own''} %> </div> </div> </div> ============================================================ 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> <p><label for="book_author" class="left"> Author</ label> <%= text_field ''newbook'', ''author'' %></p> <%= 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 } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-31 21:22 UTC
Re: Requesting help on Ajax link_to_remote RJS error
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>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 31, 2:22 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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'' > > FredThanks! 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-01 07:42 UTC
Re: Requesting help on Ajax link_to_remote RJS error
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you very much. It is working now. On Apr 1, 12:42 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---