How to write a condition when a date field should be sorted according to date filters in rails? -
i having date filters named start_date , end_date , have sort contacts based on filters , sort according created_at (a date field).
this method listing records:
def execute_records @items = [] if @params[:category_id] && !@params[:category_id].empty? contacts = contact.joins(:company).where(active: true, account_id: @user.id, companies: {category_id: @params[:category_id], active: true}) else contacts = contact.joins(:company).where(active: true, account_id: @user.id, companies: {active: true}) end contacts.includes(company: [:addresses, :category, :lead_source]).each |contact| @items << report.new(contact) if contact.is_a?(contact) end end
here in above method wanted add condition created_at in between start_date , end_date. created_at field in contacts table.
please me..
i think need this:
contact.joins(:company).where(active: true, account_id: @user.id, companies: {created_at: time.new(params[:start_date] || 0)..time.new(params[:end_date] || time.new(3000))})
Comments
Post a Comment