Ruby on Rails
Monday, July 6, 2015
Hi,
I need to implement a notification feature in my project. My user model has a daily, weekly and monthly booleans fields. I already have a UserMailer that sends mail when I create an account, or for password resetting.
What I want is my app to send a mail each day or week or month, depending on what the user chose.
So I've installed Whenever gem, and here is my schedule.rb :
My rake task :
My UserMailer :
The thing is, I don't know if I did right, and how can I test this, since I'm not in development ?
-- I need to implement a notification feature in my project. My user model has a daily, weekly and monthly booleans fields. I already have a UserMailer that sends mail when I create an account, or for password resetting.
What I want is my app to send a mail each day or week or month, depending on what the user chose.
So I've installed Whenever gem, and here is my schedule.rb :
every :day, :at => '12pm' do # Use any day of the week or :weekend,
:weekday rake "email_sender"
endMy rake task :
desc "Send email to users"
task :email_sender => :environment do |_, args|
User.find_each do |user|
UserMailer.daily_mail(user).deliver if user.daily == true
end
endMy UserMailer :
def daily_mail(user)
@user = user mail to: user.email, subject: "Mail journalier"
endThe thing is, I don't know if I did right, and how can I test this, since I'm not in development ?
I did a crontab -l and I get this :
# Begin Whenever generated tasks for: store
0 12 * * * /bin/bash -l -c 'cd /Users/Marco/Documents/TBProject && RAILS_ENV=production bundle exec rake email_sender --silent'
# End Whenever generated tasks for: store
# Begin Whenever generated tasks for: /Users/Marco/Documents/TBProject/config/schedule.rb
0 12 * * * /bin/bash -l -c 'cd /Users/Marco/Documents/TBProject && RAILS_ENV=production bundle exec rake email_sender --silent'
# End Whenever generated tasks for: /Users/Marco/Documents/TBProject/config/schedule.rb
If you could help me please
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9282be48-66f6-4c50-99f7-f1840bfdcd92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment