Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

Hi,
I need a fresh set of eyes to look at this bit of controller code and
tell
me why I might be getting an error message:
lookup = Profit.find(:all, :conditions => [ "user_id = ? AND
product_id = ?", uid, pid])
unless lookup.empty?
if (lookup.updated_on > 360.minutes.ago)
return
end
end
If lookup is empty, then I get an error message that
lookup.updated_ondoesn't exist. I've tried
lookup.nil? but lookup gets returned in the form of [] so that empty
works.
But if lookup is empty should not the code inside the statement get
ignored?
Any suggestions on how I might rework that code?
Thanks
Steve O.
http://www.smarkets.net

On 12/22/05, Steve O. <removed_email_address@domain.invalid> wrote:
> end> end>> If lookup is empty, then I get an error message that lookup.updated_on> doesn't exist. I've tried lookup.nil? but lookup gets returned in the form> of [] so that empty works. But if lookup is empty should not the code inside> the statement get ignored?>> Any suggestions on how I might rework that code?
Profit.find(:all) will return an array. The array will be empty if
none of the conditions can be satisified.
Later on, you're calling updated_on on the array object, and I don't
think that's a valid method for an array object.
You probably want to use Profit.find(:first) (or maybe even
Profit.find_by_user_id_and_product_id().