deconstructing date_select in rails

// Reconstruct a date object from date_select helper form params

// place this code into your application.rb file
def build_date_from_params(field_name, params)["#{field_name.to_s}(1i)"].to_i,

//You can changes order of displaying into view
<%= date_select ‘from’, ‘date’ ,:order => [:day, :month, :year] %>
<%= date_select ‘to’, ‘date’,:order => [:day, :month, :year]  %>

//goes into controller -- add your own error handling/defaults, please!
@from = build_date_from_params(:date, params[:from])
@to = build_date_from_params(:date, params[:to])

Comparing date time into controller

@users_reports = User.find(:all, :conditions=>[‘created_at >= ? and created_at < ?’, @to, @from])

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *