ruby on rails - running rake task from console produces 'ArgumentError: no method name given' error -
i have rake task meant call mailer , email users meet given condition. but, when call rake task console using rake nagging_email:send
following 'argumenterror: no method name given' , task not run. full console error log can seen here: https://gist.github.com/srt32/6433024
i have mailer set follows:
class workoutmailer < actionmailer::base def nagging_email(user) @user = user subject = "what have done today?" @url = 'http://frozen-taiga-7141.herokuapp.com/members/sign_in' mail to: @user.email, subject: subject.to_s end end
and rake task follows gets users meet given condition (being lazy) , calls mailer given user param:
namespace :nagging_email desc "send nagging email lazy users" task :send => :environment daily_nag end def daily_nag users = user.all users.each |user| unless last_workout(user) == date.today workoutmailer.nagging_email(user).deliver end end end def last_workout(user) user = user last_workout = user.workouts.order("date desc").limit(1) last_workout_date = last_workout.date return last_workout_date end end
any trying figure out how run rake task appreciated. thanks.
you should run rake terminal, not rails console. if reason want rails console, should load tasks that
require 'rake' myrailsapp::application.load_tasks rake::task['my_task'].invoke
Comments
Post a Comment