ruby-on-railsrubyahoy

like Operator in ahoy events


I started code rails recently and I need to figure out this problem.

%td
  = Ahoy::Event.where(name: "viewed_brochure").where_properties(brochure_id: brochure.id, time: like 'Mon%').count

this should be show the number of Mondays in database. But it doesn't work and give syntax error.

I wonder how to use like operator in this line.

Ahoy::Event.where(time: "2017-10-30 14:50:35.361999").where_properties(brochure_id: brochure.id).count

This line works fine but i need to use like operator or something similar.


Solution

  •  Ahoy::Event.where("date_part('dow', time) = 1").count
    

    This will return the count of all events created at Monday.You can add more filters.