I have a list that is being populated through an ajax response and if the number of items to be populated is zero, I would like to show a message informing the user that there is no items. Here is the portion of the rhtml file that contains the div tags that would hold the list of items and the "no items" message. <div id="show_no_results_message"> There are no tasks for this category </div> <ul> <div id="task_list"/> </ul> # The rjs file code page.replace_html("task_list", :partial => "task", :collection=> @tasks) page["show_no_results_message"].hide if @tasks.nil? || @tasks.count =0 #This is the line that doesn''t work I had it working before the ajax was inserted since it was easy to include the logic within the rhtml file to set the style (display) of the <div id="show_no_results_message"> to none. Now that it is done through ajax I am not sure how to do this without inserting the logic within the rjs file, which, I am sure is the proper way to do it, but I just can''t figure out what is wrong. There is actually 2 problems with the line marked as not working: 1) page["show_no_results_message"].hide if @tasks.nil? || @tasks.count == 0 having @tasks.count == 0 causes none of the tasks to be rendered to the list. Unfortunately, I cannot get Firebug to work on my machine so I am not exactly sure what is wrong with the condition. 2) page["show_no_results_message"].hide if @tasks.nil? Withouth the count check allows the tasks to be shown on the screen, but does not hide the "show_no_results,,," div tag. Any tips would be appreciated. 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 -~----------~----~----~----~------~----~------~--~---
The problem is in this line:>> page["show_no_results_message"].hide if @tasks.nil? || @tasks.count == 0more specifically in this condition:>> @tasks.count == 0if I make a tweak, like so:>> page["show_no_results_message"].hide if @tasks.count == 0it fails. I have also tried tacking on .to_i methods to both the count and 0, then performing the bool op, but it still does not work. On Apr 7, 7:55 pm, "chris" <olsen.ch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a list that is being populated through an ajax response and if > the number of items to be populated is zero, I would like to show a > message informing the user that there is no items. > > Here is the portion of the rhtml file that contains the div tags that > would hold the list of items and the "no items" message. > > <div id="show_no_results_message"> > There are no tasks for this category > </div> > > <ul> > <div id="task_list"/> > </ul> > > # The rjs file code > page.replace_html("task_list", :partial => "task", :collection=> > @tasks) > page["show_no_results_message"].hide if @tasks.nil? || @tasks.count => 0 #This is the line that doesn''t work > > I had it working before the ajax was inserted since it was easy to > include the logic within the rhtml file to set the style (display) of > the <div id="show_no_results_message"> to none. > > Now that it is done through ajax I am not sure how to do this without > inserting the logic within the rjs file, which, I am sure is the > proper way to do it, but I just can''t figure out what is wrong. > > There is actually 2 problems with the line marked as not working: > 1) page["show_no_results_message"].hide if @tasks.nil? || @tasks.count > == 0 > having @tasks.count == 0 causes none of the tasks to be rendered > to the list. Unfortunately, I cannot get Firebug to work on my > machine so I am not exactly sure what is wrong with the condition. > > 2) page["show_no_results_message"].hide if @tasks.nil? > Withouth the count check allows the tasks to be shown on the > screen, but does not hide the "show_no_results,,," div tag. > > Any tips would be appreciated. > > 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 -~----------~----~----~----~------~----~------~--~---
Chris Olsen wrote:> The problem is in this line: >>> page["show_no_results_message"].hide if @tasks.nil? || @tasks.count == 0 > > more specifically in this condition: >>> @tasks.count == 0 > > if I make a tweak, like so: >>> page["show_no_results_message"].hide if @tasks.count == 0 > it fails. I have also tried tacking on .to_i methods to both the > count and 0, then performing the bool op, but it still does not work.There is no count method for an array. Try @tasks.empty? instead. I also don''t think this is valid html, where you put a div as a child of a ul tag. It should only be li''s. Instead put the task list id in the ul and get rid of the div: <ul id="task_list"> </ul> -- 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 -~----------~----~----~----~------~----~------~--~---
That would make sense then :) I could''ve swear that I saw that somewhere, but now that I check my ruby book I see it isn''t a valid method. As for the div, ya I got rid of that. At one point I wasn''t sure exactly how the replace_html method worked and didn''t want to lose the ul tag. Thanks for you help. On Apr 8, 2:18 pm, Francis Sinson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Chris Olsen wrote: > > The problem is in this line: > >>> page["show_no_results_message"].hide if @tasks.nil? || @tasks.count == 0 > > > more specifically in this condition: > >>> @tasks.count == 0 > > > if I make a tweak, like so: > >>> page["show_no_results_message"].hide if @tasks.count == 0 > > it fails. I have also tried tacking on .to_i methods to both the > > count and 0, then performing the bool op, but it still does not work. > > There is no count method for an array. Try @tasks.empty? instead. > > I also don''t think this is valid html, where you put a div as a child of > a ul tag. It should only be li''s. Instead put the task list id in the > ul and get rid of the div: > > <ul id="task_list"> > </ul> > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---