[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

trouble adding date query variable

(D. Alvarado)

2/24/2008 9:24:00 PM

Hi,

I'm trying to build a search form with a date input field, displayed
like this:

<%= date_select(:purchase_date, params[:purchase_date]) %>

But I'm having trouble adding the criteria in my controller. So far,
I have:

if !search[:purchase_date].blank?
conditions << 'purchase_date >= ?'
conditions << "#{search[:purchase_date]}"
end
find(:all, :conditions => conditions, :page => {:size
=> page_size, :current => page_num} )

But the query gets run in a weird way, below:

SELECT count(ec_orders.id) AS count_ec_orders_id FROM `ec_orders`
WHERE purchase_date >= '(3i)24(1i)2006(2i)2')


What is the right way to get the date to be displayed normally in the
SQL query? - Dave
1 Answer

Ilan Berci

2/25/2008 2:25:00 PM

0

laredotornado wrote:
> Hi,
>
> I'm trying to build a search form with a date input field, displayed
> like this:
>
> <%= date_select(:purchase_date, params[:purchase_date]) %>
>
> But I'm having trouble adding the criteria in my controller. So far,
> I have:
>
> if !search[:purchase_date].blank?
> conditions << 'purchase_date >= ?'
> conditions << "#{search[:purchase_date]}"
> end
> find(:all, :conditions => conditions, :page => {:size
> => page_size, :current => page_num} )
>
> But the query gets run in a weird way, below:
>
> SELECT count(ec_orders.id) AS count_ec_orders_id FROM `ec_orders`
> WHERE purchase_date >= '(3i)24(1i)2006(2i)2')
>
>
> What is the right way to get the date to be displayed normally in the
> SQL query? - Dave

conditions => ["purchase_date >= ?", search[:purchase_date].to_s(:db)]

hth

ilan
--
Posted via http://www.ruby-....