Hello, I have one problem related to Ajax and render :partial. I develop a small search application. When there are the results that match to the user''s search, it will render the partial views of the result search to replace part of the document. However, when the result is not matched, I want to display an alert box to the user back and keep the previous result''s search on the screen without erasing it. Is there a way to cancel the render? Normally, after Ajax response, it will erase the previous content. I want to know how to prevent this? Here is my code: if @result.length > 0 render :partial => "result_list" else # ...... end Any idea? Please, help..... Thanks Chamnap --~--~---------~--~----~------------~-------~--~----~ 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 6/8/07, Chamnap <chamnapchhorn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > I have one problem related to Ajax and render :partial. I develop a > small search application. When there are the results that match to the > user''s search, it will render the partial views of the result search > to replace part of the document. However, when the result is not > matched, I want to display an alert box to the user back and keep the > previous result''s search on the screen without erasing it. Is there a > way to cancel the render? Normally, after Ajax response, it will erase > the previous content. I want to know how to prevent this? Here is my > code: > > if @result.length > 0 > render :partial => "result_list" > else > # ...... > end > > Any idea? Please, help..... >I think that you made this test in your view, or you can define another partial -- Cyril Mougel --~--~---------~--~----~------------~-------~--~----~ 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,> to replace part of the document. However, when the result is not > matched, I want to display an alert box to the user back and keep the > previous result''s search on the screen without erasing it.In your view code, in the "whatever_remote" you are using just don''t use an ":update" option. When you use update, you are telling rails to replace the html of the given element with the response of the action called. If the response is blank, then you get an empty element on screen as a result. If you are not using "update", you are telling rails not to replace anything in your view, but to have instead the flexibility to use the javascript "document" object for whatever purpose you want (usually for multiple element updates). You can use rjs (or from the controller directly a render :update) in which you can use the "page" object as a wrapper for javascript "document". When you have a result, you can do a page.replace_html your_div_id, your_content when you lack a result you can do a page.alert (''No results'') That shoudl do the trick. Regards, javier ramírez --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
render :nothing => true ? ;) Chamnap wrote:> Hello, >-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
try something like this: render :update do |page| if search_results page.replace_html ''search_results_div'', :partial => ''search_results'' else page.call ''alert'', ''No Results!'' end end On 6/8/07, Titou Titou <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > render :nothing => true ? ;) > > Chamnap wrote: > > Hello, > > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, Thanks javier ramírez and Titou Titou. It works now. Great, I learned something new from you both. Thanks Chamnap --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---