how do i define a named_scope to return all the records that were created within the last 7 days, and then how do i use that named scope in a controller?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would recommend watching the Railscast Episode on named_scope.
Ideally, the code you’re looking for would be:
This will allow you to pass a parameter to the named scope or it will default to the previous 7 days.
You would call it using: