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|%> <b>><%=item.uniquename%></b> <%end%> <%else%> <b>no selection</b> <%end%> Thank you. -- 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 -~----------~----~----~----~------~----~------~--~---
def selected conditions = [[]] params[:result].each do |result_id| conditions.first << ''feature.uniquename=?'' conditions << result_id end if params[:result] conditions[0] = conditions.first.join('' OR '') conditions=[''1=1''] if conditions.first.empty? @items= Feature.find(:all, :conditions => conditions) end -- 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 -~----------~----~----~----~------~----~------~--~---
i meant def selected conditions = [[]] params[:result].each do |result_id| conditions.first << ''feature.uniquename=?'' conditions << result_id end if params[:result] conditions[0] = conditions.first.join('' OR '') conditions=[''1=1''] if !conditions.first or conditions.first == '''' @items= Feature.find(:all, :conditions => conditions) end -- 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 -~----------~----~----~----~------~----~------~--~---
Keynan Pratt wrote:> i meant > > def selected > conditions = [[]] > params[:result].each do |result_id| > conditions.first << ''feature.uniquename=?'' > conditions << result_id > end if params[:result] > > > conditions[0] = conditions.first.join('' OR '') > conditions=[''1=1''] if !conditions.first or conditions.first > == '''' > > @items= Feature.find(:all, :conditions => conditions) > endThanks Keynan! How would i pass a message to the user informing him to make a selection? This is because with no selection the method seems make the browser hang, till i manually stop the execution. -- 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 -~----------~----~----~----~------~----~------~--~---
the browser should not be hanging. pop in a few logger.debug statements to find where your trapped in a loop. As for notifying the user def selected conditions = [[]] if params[:result] params[:result].each do |result_id| conditions.first << ''feature.uniquename=?'' conditions << result_id end else flash[:notice] = ''Please select a feature name.'' end conditions[0] = conditions.first.join('' OR '') conditions=[''1=1''] if !conditions.first or conditions.first == '''' @items= Feature.find(:all, :conditions => conditions) end -- 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 -~----------~----~----~----~------~----~------~--~---