All threads / How do I get all projects when the end date is exactly a weekly basis?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I get all projects when the end date is exactly a weekly basis?

Stephen Sizer asked in Rails

I have a project model with a start and end date.

I want to bring back all pojects that are exactly a week old, 2 weeks, 3 weeks etc

Is there a way to do this using a scope?

Thanks in advance

Something along the lines of: scope :two_weeks_ago, -> { where(end_date: 2.weeks_ago) } should do the trick.

Hi Jack,

Thanks for the reply.

that code would work for a project being 2 weeks old. Some projects may run for a year and i want to run some code every week.

To give you more context...

Every week I want to create a review for the project. So after 1 whole week a review gets created for the project manager to fill out. After 2 weeks, 3 weeks, 4 weeks ... 27 weeks and so on until the project finishes.

Thanks,
Steve

So a Project has_many :reviews? Correct?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.