Like carvil, I have a datetime in my model for created_at, although I wanted the predicate "equals" to compare created_at and date (for example, "2012-09-26").
So, I added to my model (to add cast attributes and remove the old created_at / update_at / deleted_at file:
ransacker :created_at do
Arel::Nodes::SqlLiteral.new("date(items.created_at)")
end
ransacker :updated_at do
Arel::Nodes::SqlLiteral.new("date(items.updated_at)")
end
ransacker :deleted_at do
Arel::Nodes::SqlLiteral.new("date(items.deleted_at)")
end
UNRANSACKABLE_ATTRIBUTES = ["created_at", "updated_at", "deleted_at"]
def self.ransackable_attributes auth_object = nil
(column_names - UNRANSACKABLE_ATTRIBUTES) + _ransackers.keys
end
But when I confirm the request (created_at is "2012-03-24"), I have this error:
NoMethodError (undefined method `name' for "date(items.created_at)":Arel::Nodes::SqlLiteral):
Surprisingly, it works with more than and less than. This error has only an "equal."
I did all this for all my models and 60% work (40% this error occurs).
In the console:
irb(main):232:0> Item.search(:created_at_eq => Date.today.to_s).result
(Object doesn't support #inspect)
thanks for the help
EDIT:
I have a default_scope that does: Element (: deleted_at false)
But I do not know why the error occurs