I had everything rendering properly before the ajax was introduced. Now the javascript is being rendered out to the html page. #Here is the list that the items are to be rendered out to <ul id="task_list"></ul> #the controller method calling on the rjs file def show_tasks @tasks = Task.find(:all, :conditions => ["category_id = ?", params[:id]]) end #the _task.rhtml file <li> <%= task.name %> <%= link_to "View", :controller => "task", :action=> :show, :id => task %> <%= link_to "Edit", :controller => "task", :action=> :edit, :id => task %> <%= link_to "Delete", {:controller => "task", :action=> :delete, :id=>task}, {:confirm=>"Are you sure you want to delete this task", :method=>:post } %> </li> #and finally the element that the bad output is rendered to <div id="task_list">try { Element.update("task_list", "<li>\n blah blah blah\n <a href="%5C%22/ task/show/22%5C%22">View</a>\n <a href="%5C%22/task/edit/22%5C %22">Edit</a>\n <a href="%5C%22/task/delete/22%5C%22" method="\"post\"" onclick=''\"return'' confirm(="" are="" sure="" you="" want="" to="" delete="" this="" task="" );\="">Delete</ a>\n</li>\n"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''Element.update(\"task_list\", \"<li>\n blah blah blah\n <a href="%5C%5C%22/task/show/22%5C%5C%22">View</a>\n <a href="%5C%5C%22/ task/edit/22%5C%5C%22">Edit</a>\n <a href="%5C%5C%22/task/delete/22%5C %5C%22" method="\\"post\\"" onclick=''\\"return'' confirm(\="" are="" sure="" you="" want="" to="" delete="" this="" task\="" );\ \="">Delete</a>\n</li>\n\");''); throw e }</div> </div> Any help is appreciated --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Chris, chris wrote:> Now the javascript is being rendered out to the html page. > > #the controller method calling on the rjs fileWhat does show_tasks.rjs contain? It looks like that may be where your problem is. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oops forgot about that one, here it is ===page.replace_html("task_list", :partial => "task", :collection=> @tasks) === It also seems that the rhtml portion containing the error, was taken after trying to come up with a solution, which is the reason it is within a div tag. It should be within a ul tag <div id="task_list">try { --> <ul id="task_list">try { ... Thanks for the help On Apr 3, 5:40 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Chris, > > chris wrote: > > Now the javascript is being rendered out to the html page. > > > #the controller method calling on the rjs file > > What does show_tasks.rjs contain? It looks like that may be where your > problem is. > > Best regards, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Chris, chris wrote:> ===> page.replace_html("task_list", :partial => "task", :collection=> > @tasks) > ===> > On Apr 3, 5:40 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >> Hi Chris, >> >> chris wrote: >> > Now the javascript is being rendered out to the html page. >> >> > #the controller method calling on the rjs file >> >> What does show_tasks.rjs contain? It looks like that may be where your >> problem is.I should have asked you for both views, not just the .rjs. My apologies for the extra turn-around. Your rjs looks fine. What appears to be happening is that rjs is sending the correct stuff to the browser, but the browser is either expecting html rather than js and so is rendering it rather than executing it, or the browser doesn''t know how to execute it. For case 1, check the method you''re using to invoke the show_tasks method. If it''s a link, for example, the method should be link_to_remote, not link_to. Your view needs to be using something that submits using XMLHttpRequest, not a straight POST or GET. That''s how the browser knows to expect a js response that it should execute rather than simply display. If that''s already in place, then check your application.rhtml or controller-specific layout if applicable. It needs to have this in the <head> section: <%= javascript_include_tag :defaults %>. That includes all the prototype js files you need for the browser to actually execute the js it receives. Hope that helps, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I do have the javascript_include_tag :defaults As for the link_to, that is that thing that puzzles me, since the links that appear are hard links to a separate page, it is the hard links appearing that is contained within the ajax. I really don''t know why the javascript is rendering out there. here is the main page, which has a list of categories on the left side, then after clicking on one of them the ajax kicks in and shows the related tasks on the right side =========<% unless flash[:notice].nil? %> <div> <%= flash[:notice] %> </div> <% end %> <div style="float: left; width: 300px;"> <h2>Categories</h2> <%= link_to "Add Category", :controller => "category", :action => :create %> <ul> <%= render :partial => "category", :collection => @categories %> </ul> </div> <div style="float:right; width: 300px;"> <h2>Tasks</h2> <%= link_to "Create New Task", :controller => "task", :action => :create, :id => params[:id] unless params[:id].nil? %> <div style="display:<%= show_no_results(@tasks.length) %>"> There are no tasks for this category </div> <ul id="task_list"></ul> </div> ============Once again here is the category partial that appears on the left side ============<li> <a href="#" onclick="<%= remote_function :update => ''task_list'', :url => {:action => :show_tasks, :id => category} %>"> <%= category.name unless category.nil? %> </a> </li> ============And here is the partial that shows the task details on the right side of the screen ============<li> <%= task.name %> <%= link_to "View", :controller => "task", :action=> :show, :id => task %> <%= link_to "Edit", :controller => "task", :action=> :edit, :id => task %> <%= link_to "Delete", {:controller => "task", :action=> :delete, :id=>task}, {:confirm=>"Are you sure you want to delete this task", :method=>:post }%> </li> ============ I have even removed the link_to items, just leaving the task name, and I still get all the javascript rendering out to the browser. Thanks for you help On Apr 4, 5:29 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > I should have asked you for both views, not just the .rjs. My apologies for > the extra turn-around. Your rjs looks fine. What appears to be happening > is that rjs is sending the correct stuff to the browser, but the browser is > either expecting html rather than js and so is rendering it rather than > executing it, or the browser doesn''t know how to execute it. For case 1, > check the method you''re using to invoke the show_tasks method. If it''s a > link, for example, the method should be link_to_remote, not link_to. Your > view needs to be using something that submits using XMLHttpRequest, not a > straight POST or GET. That''s how the browser knows to expect a js response > that it should execute rather than simply display. If that''s already in > place, then check your application.rhtml or controller-specific layout if > applicable. It needs to have this in the <head> section: <%> javascript_include_tag :defaults %>. That includes all the prototype js > files you need for the browser to actually execute the js it receives. > > Hope that helps, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I should also add that the ajax is working fine when clicking on the category links on the left side of the screen (no postback), it is just the task items on the left side of the screen that then render out javascript that is the problem. The html containing the rendered ajax was using an addon in firefox to obtain the html contained within the DOM, but not actually rendered out to the page. (that is kind of a key point, not sure how I left it out before) On Apr 4, 6:53 am, "chris" <olsen.ch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I do have the javascript_include_tag :defaults > > As for the link_to, that is that thing that puzzles me, since the > links that appear are hard links to a separate page, it is the hard > links appearing that is contained within the ajax. I really don''t > know why the javascript is rendering out there. > > here is the main page, which has a list of categories on the left > side, then after clicking on one of them the ajax kicks in and shows > the related tasks on the right side > =========> <% unless flash[:notice].nil? %> > <div> > <%= flash[:notice] %> > </div> > <% end %> > > <div style="float: left; width: 300px;"> > <h2>Categories</h2> > <%= link_to "Add Category", :controller => "category", :action > => :create %> > <ul> > <%= render :partial => "category", :collection => @categories %> > </ul> > </div> > > <div style="float:right; width: 300px;"> > <h2>Tasks</h2> > <%= link_to "Create New Task", > :controller => "task", > :action => :create, > :id => params[:id] unless params[:id].nil? %> > > <div style="display:<%= show_no_results(@tasks.length) %>"> > There are no tasks for this category > </div> > > <ul id="task_list"></ul> > </div> > ============> Once again here is the category partial that appears on the left side > ============> <li> > <a href="#" > onclick="<%= remote_function :update => ''task_list'', :url => > {:action => :show_tasks, :id => category} %>"> > <%= category.name unless category.nil? %> > </a> > </li> > ============> And here is the partial that shows the task details on the right side > of the screen > ============> <li> > <%= task.name %> > <%= link_to "View", :controller => "task", :action=> :show, :id => > task %> > <%= link_to "Edit", :controller => "task", :action=> :edit, :id => > task %> > <%= link_to "Delete", {:controller => "task", :action=> :delete, > :id=>task}, > {:confirm=>"Are you sure you want to delete > this task", > :method=>:post > }%> > </li> > > ============> > I have even removed the link_to items, just leaving the task name, and > I still get all the javascript rendering out to the browser. > > Thanks for you help > > On Apr 4, 5:29 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: > > > > > I should have asked you for both views, not just the .rjs. My apologies for > > the extra turn-around. Your rjs looks fine. What appears to be happening > > is that rjs is sending the correct stuff to the browser, but the browser is > > either expecting html rather than js and so is rendering it rather than > > executing it, or the browser doesn''t know how to execute it. For case 1, > > check the method you''re using to invoke the show_tasks method. If it''s a > > link, for example, the method should be link_to_remote, not link_to. Your > > view needs to be using something that submits using XMLHttpRequest, not a > > straight POST or GET. That''s how the browser knows to expect a js response > > that it should execute rather than simply display. If that''s already in > > place, then check your application.rhtml or controller-specific layout if > > applicable. It needs to have this in the <head> section: <%> > javascript_include_tag :defaults %>. That includes all the prototype js > > files you need for the browser to actually execute the js it receives. > > > Hope that helps, > > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Chris, chris wrote:> > I should also add that the ajax is working fine when clicking on the > category links on the left side of the screen (no postback),>> <h2>Categories</h2> >> <%= link_to "Add Category", :controller => "category", >> :action => :create %>Not sure what you mean here. If the above is what you''re referring to, there is no Ajax taking place via the category links. Clicking on the "Add Category" link sends a straight Http GET to the server. The server is sending back html which, because it sent a request using Http, the browser is rendering correctly.> it is just the task items on the left side of the screen > that then render out javascript that is the problem.>> <%= render :partial => "category", :collection => @categories %>>> ============>> Once again here is the category partial that appears on the left side >> ============>> <li> >> <a href="#" >> onclick="<%= remote_function :update => ''task_list'', :url => >> {:action => :show_tasks, :id => category} %>"> >> <%= category.name unless category.nil? %> >> </a> >> </li> >> ============In both cases you''re using straight links to invoke controller methods which causes the browser to expect an html response. The difference between the situation above and this one is that in the one above you''re sending back html and in this one you''re sending back js. So... 1) Assuming that you''re category object is getting generated by enumerating a instance variable, I think if you replace the <a...></a> with <%= link_to_remote(category.name, :url =>{:action => ''show_tasks'', ::id => category}) %> your problem will be fixed. 2) Spend the $9.95 to pick up Cody Fauser''s RJS tutorial (in PDF) from O''Reilly. It''ll put you on the right track. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I bought the book, and as you mentioned the better way to do it was using the link_to_remote method. All is working now nicely. Thanks for the help. On Apr 4, 8:09 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Chris, > > chris wrote: > > > I should also add that the ajax is working fine when clicking on the > > category links on the left side of the screen (no postback), > >> <h2>Categories</h2> > >> <%= link_to "Add Category", :controller => "category", > >> :action => :create %> > > Not sure what you mean here. If the above is what you''re referring to, > there is no Ajax taking place via the category links. Clicking on the "Add > Category" link sends a straight Http GET to the server. The server is > sending back html which, because it sent a request using Http, the browser > is rendering correctly. > > > it is just the task items on the left side of the screen > > that then render out javascript that is the problem. > >> <%= render :partial => "category", :collection => @categories %> > >> ============> >> Once again here is the category partial that appears on the left side > >> ============> >> <li> > >> <a href="#" > >> onclick="<%= remote_function :update => ''task_list'', :url => > >> {:action => :show_tasks, :id => category} %>"> > >> <%= category.name unless category.nil? %> > >> </a> > >> </li> > >> ============> > In both cases you''re using straight links to invoke controller methods which > causes the browser to expect an html response. The difference between the > situation above and this one is that in the one above you''re sending back > html and in this one you''re sending back js. So... > > 1) Assuming that you''re category object is getting generated by enumerating > a instance variable, I think if you replace the <a...></a> with > <%= link_to_remote(category.name, :url =>{:action => ''show_tasks'', ::id => > category}) %> > your problem will be fixed. > 2) Spend the $9.95 to pick up Cody Fauser''s RJS tutorial (in PDF) from > O''Reilly. It''ll put you on the right track. > > Best regards, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---