Skip to main content

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

Rails • Asked by Stephen Sizer

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?



Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.