activeadmin-plugins / active_admin_datetimepicker

:calendar: active_admin_datetimepicker gem
MIT License
72 stars 48 forks source link

How use "date_time_range" in a custom filter? #66

Closed eugenio-caicedo closed 4 years ago

eugenio-caicedo commented 4 years ago

I need a custom param but It's not an attribute of my model. I need this param to filter the table with different columns. This is an example:

models/my_model.rb

class MyModel < ActiveRecord::Base
  #attributes: create_at, update_at
end

admin/my_model.rb

ActiveAdmin.register Team do
  filter :date, as: :date_time_range

  controller do
    def scoped_collection
       #filter here
    end
  end
end

But I get an error with that implementation.

undefined method `date_gteq_datetime_picker' for Ransack::Search<class: MyModel, base: Grouping <combinator: and>>:Ransack::Search

I guess the date column is not an attribute.

workgena commented 4 years ago

Yes, MyModel should have column in database named "date" with type as timestamp of date format.

eugenio-caicedo commented 4 years ago

Umm ok, thanks for the help.

Fivell commented 4 years ago

@eugenio-caicedo aa supports custom filters using ransackable scopes try such approach https://stackoverflow.com/questions/48776246/custom-activeadmin-filter-for-date-range-complex-logic-in-method

eugenio-caicedo commented 4 years ago

@Fivell I'm not sure but I'll try to do it. Thanks for the suggestion.