Select in Static Context

0 views
Skip to first unread message

Jeff Casimir

unread,
Feb 21, 2008, 1:13:54 PM2/21/08
to ambit...@googlegroups.com
Howdy,

I'm pretty novice to Ambition and have one frequent stumbling block.
Often at the console I want to do simple searches like this...

recent = Message.select{|m| m.created_on == Date.today}

But I get an error about "private method `select' called for
#<Class:0x37519dc>". Is there some reason doing this static query is
"wrong"?

Thanks,
Jeff

Josh

unread,
Feb 21, 2008, 11:46:24 PM2/21/08
to ambition.rb
You should be able to do something like:

date = Date.today
recent = Message.select{|m| m.created_on == date}

I don't remember the specific explanation of why you can't do
something like what you first posted though.

- Josh

Chris Wanstrath

unread,
Feb 23, 2008, 2:39:41 PM2/23/08
to ambit...@googlegroups.com
On 2/21/08, Jeff Casimir <je...@casimircreative.com> wrote:

> recent = Message.select{|m| m.created_on == Date.today}
>
> But I get an error about "private method `select' called for
> #<Class:0x37519dc>". Is there some reason doing this static query is
> "wrong"?

This should work fine. Did you require the proper AR adapter?

>> require 'ambition/adapters/active_record'
=> []
>>
?> recent = Message.select{|m| m.created_on == Date.today}
=> (Query object: call #to_s or #to_hash to inspect, call an
Enumerable (such as #each or #first) to request data)
>> recent.to_s
=> "SELECT * FROM messages WHERE messages.`created_on` = '2008-02-23'"

- Chris

Reply all
Reply to author
Forward
0 new messages