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.
There are no tasks for this category
# The rjs file code
page.replace_html("task_list", :partial => "task", :collection=>
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
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.