Datetime to date search #143

Epiju opened this Issue Sep 26, 2012 · 1 comment


None yet

2 participants

Epiju commented Sep 26, 2012


I have in my model a datetime for created_at although I wanted the "equals" predicate to compare the created_at and a date (like '2012-09-26').

So I added in my model (in order to add casted attributes and take off the old created_at/update_at/deleted_at :

ransacker :created_at do"date(items.created_at)")

  ransacker :updated_at do"date(items.updated_at)")

  ransacker :deleted_at do"date(items.deleted_at)")

  # Hide some attributes for advanced search
  UNRANSACKABLE_ATTRIBUTES = ["created_at", "updated_at", "deleted_at"]

  def self.ransackable_attributes auth_object = nil
    (column_names - UNRANSACKABLE_ATTRIBUTES) + _ransackers.keys

But when I confirm the query (created_at equals to '2012-03-24') I have this error:

NoMethodError (undefined method `name' for "date(items.created_at)":Arel::Nodes::SqlLiteral):

Surprisingly, it works with "greater than" and "less than". Only "equals" occurs this error.

I made all of this for all my models and 60% works (the remain 40% occurs this error).

In the console :

irb(main):232:0> =>
(Object doesn't support #inspect)

Thanks for your help


I have a default_scope which makes :
Item(:deleted_at false)

But I don't know why it occurs the error

jonatack commented Sep 5, 2014

The Ransackers section of the wiki explains how to do this.

@jonatack jonatack closed this Sep 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment