checkboxes validation

George George
Thu, 17 May 2007 04:49:10 -0000

Hi Guys
i have this method for finding a list of items via check-boxes
    def selected
        conditions = [[]]
        params[:result].each do |result_id|
            conditions.first << ''feature.uniquename=?''
            conditions << result_id
            end


         conditions[0] = conditions.first.join('' OR '')
         conditions=[''1=1''] if conditions.empty?

         @items= Feature.find(:all, :conditions => conditions)
     end

however when no checkbox is checked and one  hits the select button i
get this error.
"NoMethodError (You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each):"


i would like to either trap the error and display it in a "friendly
way"
or not display anything at all.

i tried this in my view but it does not seem to help
<% if @items.length > 0 %>

<%@items.each do|item|%>
><%=item.uniquename%>
<%end%>

<%else%>
no selection
<%end%>


Thank you.