I am trying to set up a custom rake task for a Rails app that checks to see if your location is within a certain area with street cleaning restrictions. If it is, you can click a button "Remind Me" that will save the user id and restriction id to a reminder table.
I have the Rufus gem running the rake task every 15 minutes.
What I then want is the rake task to check the current time and day with the day and start time that corresponds with the restriction id, and if it is within 30 minutes, it should email the user to move their car.
When I run my current code below, I get this error:
rake aborted!
undefined method `reminders' for # <ActiveRecord::Relation::ActiveRecord_Relation_Day:0x007fb38c3274f8>
/Users/m/WDI/park_pointer/lib/tasks/reminder.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => reminder:mail_users
Here's my entire project: https://github.com/mnicole/park_pointer
But the code for the rake task is:
namespace :reminder do
desc "REMINDER"
task :mail_users => :environment do
time = Time.new
t = Time.now
today = Day.where(:id => time.wday + 1) #returns 0 for sunday, etc
@reminders = today.reminders
@reminders.each do |reminder|
@reminder = reminder
reminder_time_in_mins = restriction.start_time.hour * 60
current_time_in_mins = (Time.now.hour * 60) + Time.now.min
# last_time_in_mins = record.last.hour * 60 + record.last.min
if current_time_in_mins > (reminder_time_in_mins - 30)
@user = User.find(reminder.user_id.last)
UserMailer.reminder_email(user_id).deliver!
end
end
end
end
I THINK I'm almost there, but I've been working on this for a few months and am kind of at a loss about the next step.
Thanks in advance!!
-Michele