Home Ask Login Register

Developers Planet

Your answer is one click away!

Rails Coder. February 2016

Date filter not displaying

I created a new datetime row for a page, it works well. The column displays all the specific dates, but when I want to show specific rows using a date filter, it doesn't display a thing.

In the model:

 before_validation :payment_date

 def payment_date
  self.payment_date = sales_order.payment_transactions.last.date

The date filter from the controller file:

   filter :payment_date, :as => :date_range, :collection => proc { Complaint.all.map{|c| c.sales_order.try(:payment_transactions).try(:last).try(:date)} }

I suppose I did a couple of mistakes and i'm curious where the bad coding is.


Andrey Deineko February 2016

In AA filtering is based on Ransack, so your filter would look as follows (assuming sales_order is an association on your model):

filter :sales_order_payment_transactions_date, label: 'Some label', as: :date_range

Here you basically go along the association chain - it is acceptable with ransack.

Post Status

Asked in February 2016
Viewed 3,674 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life