undefined method `delay' for UserMailer:Class - ruby-on-rails

I am getting the following error while writing mail notification process asynchronously by using delay method.
NoMethodError in SampleController#create
undefined method `delay' for UserMailer:Class
I have the following code in my controller.
UserMailer.delay.idea_author_notification(self,nfication)
I have already installed delayed_job gem also started delayed_job by using jobs:work rake task.
Shall I need to do some other changes for using delay method for executing mail related code in background ?
Please help me on this asap..
Thanks in advanced...

the method delay is not existed for any action mailer class. So you can not call that method for the UserMailer:Class.
For that you can check all the methods for the mailer class in the rails console. i.e
UserMailer.methods
and to check particular method existed or not, run the following line.
UserMailer.methods.include?(:delay)
The above line returns false
OR
if you want to use delayed jobs, please go through the following link in github. It would definitely help you.
delayed_jobs_for_rails2.x.x

Related

How to download ActiveStorage attachments to tmpdir

The objective is to download an attached file to tempdir for subsequent usage. The documentation says to use ActiveStorage::Blob#open which seems simple enough.
I'm getting errors so please explain what I'm doing wrong:
Calling #flower.photo.open results in NoMethodError (private method 'open' called for #<ActiveStorage::Attached::One:0x00007f9780625100>)
Calling #flower.photo.blob.open` results in NoMethodError (private method 'open' called for #<ActiveStorage::Blob:0x00007f9780615c50>)
Examining the source code I'm not sure why I'm getting the private method error.
That method isn't released until rails 6 next year.
There’s a similar SO question here with more info and a recommendation.

Feedzirra::Feed.fetch_and_parse(url) returns null when called by Delayed::Job

Feedzirra::Feed.fetch_and_parse(url) isn't called directly. I have a FeedJob that is called by DJ. The job does a Feed.find(id_passed_into_feed_job).update_feed. The update_feed method has the call to Feedzirra. When I call update_feed from within the console, everything works as expected. When DJ makes the call, Feedzirra::Feed.fetch_and_parse returns nil.
What is the difference between the environments of console and DJ that would cause this problem?
How do I troubleshoot what is wrong with Feedzirra::Feed.fetch_and_parse?
The problem ended up being with the New Relic gem. See this bug report: https://github.com/pauldix/feedzirra/issues/167
The fix is to add
disable_curb: true
to the newrelic.yml

Herkou class changes not detected

I'm using Herkou for some Rails 3 hosting. I have pushed code to Heroku, and I am getting the following error from the logs:
NoMethodError (undefined method `format_date' for #<Project:0x00000001938f40>):
This method does exist! I can for example so this:
$heroku console
>> Project.format_date('2011-07-07 10:50')
=> "2011-07-07"
So my code appears to be deployed. Project responds to format_date.
I also tried heroku restart with no success.
Can anyone help me? Any and all suggestions are appreciated!
Are you sure you are calling format_date on the class itself, like you do in your example, and not on an instance of the class? I.e. Project.new.format_date("2011-07-07 10:50")

Rails 3 - Delayed_Job

I'm working to learn how to user delayed_job on my rails 3 + heroku app.
I currently have the following which emails on a request (not delayed job) but it works!
UserMailer.conversation_notification(record.commentable, participant, record, #comments).deliver
I updated that to this to start using delayed_job:
Delayed::Job.enqueue UserMailer.conversation_notification(record.commentable, participant, record, #comments).deliver
But that error'd with: "ArgumentError (Cannot enqueue items which do not respond to perform):"
I also tried:
UserMailer.delay.conversation_notification(record.commentable, participant, record, #comments)
But that error'd with:
NoMethodError (undefined method `delay' for UserMailer:Class):
Any delayed_job guru's out there? Thanks
From the docs https://github.com/collectiveidea/delayed_job
Your second method was correct which removes the .deliver method:
UserMailer.delay.conversation_notification(record.commentable, participant, record, #comments)
If you are getting an undefined method delay did you add DelayedJob to the Gemfile?
gem "delayed_job"
Since including the delayed_job will add the "delay" method to everything.
I have mixed results with using delay, and I've found it very challenging to debug. So you are not alone! But when you get it working, its worth it.
I've learned to save my object before calling delay on it. Typically I will trigger my job from an after_save call back.
As an experiment, for awhile I was using a different pattern. I'd create a job object for each job that I have. For example, I would call
Delayed::Job.enqueue(PersonJob.new(#person.id))
Elsewhere in my project I would create the job object. In Rails 2, I put these in lib/ if you do that with rails 3, you need to alter the application.rb config.autload_path
class PersonJob < Struct.new(:person_id)
def perform
person = Person.find(person_id)
#do work
end
end
config.autoload_paths += Dir["#{config.root}/lib/**/"]
I just had a look at the documentation, it's been a while since I actually used delayed_job...
Jobs are Ruby objects with a method called perform, so you'd need enqueue an object which does
UserMailer.conversation_notification(record.commentable, participant, record, #comments).deliver
in its perform method.
Alternatively, you can use send_later:
UserMailer.conversation_notification(record.commentable, participant, record, #comments).send_later(:deliver)

How can i send emails with delayed_job

I'm trying to use delayed_job to send emails from an input form. In my view i have replaced the line
Emailer.deliver_signup(#usercontact)
with
Emailer.send_later(:deliver_signup, #usercontact)
but when i run the job with rake jobs:work, i get: undefined method 'deliver_signup' for "CLASS:Emailer":String
What am I doing wrong? (Note that the code works without delayed_job)
Delayed job mailer might help rather than trying to implement the details yourself.

Resources