I'm planning to write the rake task to query few details from the model and 
sending the notification using ActionMailer object

I'm getting below error when I invoke the action mailer class in my rake 
task,

rake aborted!
#<NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]>
C:/Rails application/TEST/lib/tasks/notifier.rak

My code:
notifier.rake file under lib/tasks

task :notify => :environment do 
   begin

   **************
Notifier.deliver_submitted_list_notification(email_settings[RAILS_ENV], 
records )
end

notifier.rb model/notifier.rb
class Notifier < ActionMailer::Base
def submitted_list_notification(settings,records)

**********
end
end

Any help would be appreciated!!

On Thursday, July 29, 2010 11:36:45 PM UTC-7, genericpenguin wrote:
>
> Hi guys
>
> I'm trying to use ActionMailer to send notifications outside of my 
> controllers from a rake task but I'm getting an error saying the method is 
> undefined.
>
> NoMethodError: undefined method `hour_record_expiry_notification' for 
> Notifier:Class
>
> The ActionMailer class looks like this:
>
> class Notifier < ActionMailer::Base
>   ADMIN_ADDRESS = "XXXXX@XXXXX"
>   def hour_record_expiry_notification(recipient,hour_record)
>     recipients recipient.email_address_with_name
>     from       ADMIN_ADDRESS
>     subject    "Freetime: WARNING - Hours expire in 10 days or less"
>     body       :user => recipient, :hour_record => hour_record
>     content_type "text/html"
>   end
> end
>
> and the rake task looks like this:
>
> namespace :freetime do
>   desc "Find hours that will expire soon and notify the owners"
>   task :notify_expiry => :environment do
>     a = User.find(5);b = HourRecord.find(129)
>     Notifier.hour_record_expiry_notification(a,b)
>     Rails.logger.info "Sent users expiry notifications."
>   end
> end
>
> Notifier.instance_methods shows the method but I'm thinking there's some 
> tricker involved since it isn't an instance. :)
>
> I've googled around but I can't find anyone having the same problem which 
> leads me to believe I'm doing something stupid or nobody does mail 
> notifications with rake (This is a one off that runs from a cron job). Any 
> ideas? I normally would crack my head a bit more but it's 4:30 and if I go 
> home without solving it, I'll have to use the old shotgun.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rails-oceania+unsubscr...@googlegroups.com.
To post to this group, send email to rails-oceania@googlegroups.com.
Visit this group at http://groups.google.com/group/rails-oceania.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to