Hi all,
I''m using twice the select_date function in my view to select a date
from and a date until for a date property in my model called
"written_on".
<p><label for="proposal_written_from">Written
between</label><br/>
<%= select_date nil, :prefix => "written_from",
  :order => [:day, :month, :year],
  :include_blank => true %></p>
<p><label
for="proposal_written_until">and</label><br/>
<%= select_date Date.today, :prefix => "written_until",
  :order => [:day, :month, :year],
  :include_blank => true %></p>
In my model, I want to create a date range if the user has selected
valid values for both the date written_from and the date written_until.
The POST parameters for written_from and written_until look like this:
Parameters: {"commit"=>"Find",
"written_until"=>{"month"=>"1",
"day"=>"20", "year"=>"2007"},
"action"=>"find_proposals",
"controller"=>"proposals",
"proposal"=>{"client_firstname"=>"",
"client_surname"=>"", "city"=>"",
"box"=>"", "postal_code"=>"",
"number"=>"", "units"=>"",
"policy_number"=>"", "street"=>"",
"agent_id"=>""},
"written_from"=>{"month"=>"1",
"day"=>"2",
"year"=>"2007"}}
Basically I just want to create a range like (date_from..date_until)
that I can use with the ez_where plugin for a SQL BETWEEN condition.
I tried to create the dates like this:
written_from = Date.civil(p[:written_from][:year],
p[:written_from][:mon], p[:written_from][:day])
written_until = Date.civil(p[:written_until][:year],
p[:written_until][:mon], p[:written_until][:day])
but that doesn''t seem to work. The ez_where condition would look
something like:
cond = Condition.new do
  written_on <=> (date_from..date_until) unless date_from.nil? ||
date_until.nil?
end
Can anybody help me out with this? The ez_where plugin can be found at
http://brainspl.at/articles/2006/01/30/i-have-been-busy
Thanks for your reply,
Mark
-- 
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
-~----------~----~----~----~------~----~------~--~---