date\选择pass date以便ruby可以读取它

date\选择pass date以便ruby可以读取它,ruby,forms,datetime,Ruby,Forms,Datetime,我选择了这个日期: date_select("start_date_variable", "start_date_attribute", :start_year => 2014, :end_year => 2016, :order => [:day, :month, :year], :use_short_month => true,

我选择了这个日期:

date_select("start_date_variable", 
            "start_date_attribute", 
            :start_year => 2014, 
            :end_year => 2016, 
            :order => [:day, :month, :year], 
            :use_short_month => true, 
            :add_month_numbers => true)
将参数中的日期返回为:

"start_date_variable" => {
                          "start_date_attribute(3i)"=>"14",
                          "start_date_attribute(2i)"=>"8", 
                          "start_date_attribute(1i)"=>"2016"
                         }
我可以从中获取日期、月份和年份,但我想用以下内容搜索数据库:

@orders_from = @fulfillable_orders.where('created_at >= :start_date_par,
                                         :start_date_par => params[:start_date_variable])
但是,我不知道如何以ruby能够识别、读取和返回记录的格式传递日期

有没有线索说明这是怎么可能的,或者有什么不同的方法?

试试这个:

date_hash = {
  "start_date_attribute(3i)"=>"14", 
  "start_date_attribute(2i)"=>"8", 
  "start_date_attribute(1i)"=>"2016"
}

# will be: '2016-8-14'
date_string = date_hash.values.join('-').reverse

Date.parse(date_string)
编辑:

要对日期格式进行更严格的验证,可以使用date#strtime:

你可以试试这个宝石

Date.strptime(date_string', '%Y-%m-%d')