From: PullMonkey Date: 2008-02-10T11:15:51+09:00 Subject: Re: Right way to access an array passed as an argument? ------=_Part_3555_15987655.1202609758279 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline You probably want is_blank? since search[:user_type_id] is a value. is_blank? returns true if nil or an empty string is_empty? returns true if the array has no elements On Feb 9, 2008 7:09 PM, laredotornado wrote: > Hi, > > In my user model class, I have: > > class User < ActiveRecord::Base > ... > def self.search(search) > conditions = [] > if ! > search[:user_type_id].is_empty? # line > 26 > conditions << 'user_type_id = ?' << > "#{search[:user_type_id]}" > end > if !search[:ship_to_first_name].is_empty? > conditions << 'ship_to_first_name LIKE ?' << > "%#{search[:ship_to_first_name]}%" > end > if !search[:ship_to_last_name].is_empty? > conditions << 'ship_to_last_name LIKE ?' << > "%#{search[:ship_to_last_name]}%" > end > find(:all, :conditions => conditions ) > end > > I am passing my "params" array to this function. The array params > contains a hidden field, "user_type_id," that is always defined. But > when I execute the above, I get the error > > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.is_empty? > RAILS_ROOT: /usr/local/apache2/htdocs/easyrx > Application Trace | Framework Trace | Full Trace > app/models/user.rb:26:in `search' > app/controllers/super_admin/subscriber_controller.rb:15:in > `searchresults' > > > so I'm thinking "search[:user_type_id]" is not the right way to access > the parameter value. If I try ":search[:user_type_id]", I also get > the error. > > Thanks for any help, - Dave > > > ------=_Part_3555_15987655.1202609758279--