Skip to content Skip to sidebar Skip to footer

Ruby Strftime '%-m' Not Working In Query

My goal is to query Items by their user_id, year created, and month created. I am using sqlite3 in development and postresql in production on Heroku. I want to do something like th

Solution 1:

I would not use different databases in development and production, use the same one. Just configure postgresql on your localhost and change your query to something like:

user.items.where("date_part('year', created_at) = :year AND date_part('month', created_at) = :month", year: 2015, month: 6)

That's assuming that you have the associations setup between items and users, then you don't need to query on user_id as well.

Post a Comment for "Ruby Strftime '%-m' Not Working In Query"