Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
am trying to show pictures from database where they been uploaded withing the same week and have like. here is how i do it
def trending_wide
# binding.pry
date = DateTime.now.utc
likes = Like.where('created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week).select(:selfy_id)
time = 'created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week
top = Selfy.where(id: likes, created_at: time)
top.order("COALESCE(likes_count, 0) DESC").limit(6)
and am getting this error
PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type timestamp: "created_at >= ? and created_at <= ?"
LINE 1: ...23:59:59.999999')) AND "selfies"."created_at" IN ('created_a...
: SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "selfies" WHERE "selfies"."id" IN (SELECT "likes"."selfy_id" FROM "likes" WHERE (created_at >= '2017-02-20 00:00:00' and created_at <= '2017-02-26 23:59:59.999999')) AND "selfies"."created_at" IN ('created_at >= ? and created_at <= ?', '2017-02-20 00:00:00', '2017-02-26 23:59:59.999999') LIMIT $1) subquery_for_count
what am i doing wrong here
–
–
–
# binding.pry
date = DateTime.now.utc
likes = Like.where('created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week).select(:selfy_id)
top = Selfy.where(id: likes, created_at: Time.current.all_week)
top.order("COALESCE(likes_count, 0) DESC").limit(6)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.