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

Reply

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

Reply

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

Reply

So a Project has_many :reviews? Correct?

Reply

This is correct :)

Reply
Join the discussion
Create an account Log in

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

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

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