CC Evans

Joined

20 Experience
0 Lessons Completed
0 Questions Solved

Activity

How would I apply a scope? Like one of these.

scope :draft, ->{where(published_at: nil)}
scope :published, ->{where.not(published_at: nil).where("published_at <= ?", Time.now.in_time_zone("Eastern Time (US & Canada)"))}
scope :scheduled, ->{where.not(published_at: nil).where("published_at >= ?", Time.now.in_time_zone("Eastern Time (US & Canada)"))}
scope :pastevent, ->{where("event_end <= ?", Time.now.in_time_zone("Eastern Time (US & Canada)"))}

How would I search a Post model where I wanted only see published post? Can't figure out how the code should look in the controller index.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.