AnApprentice
AnApprentice

Reputation: 110960

NoMethodError: undefined method - How to find a method?

I'm getting the following error:

#<NoMethodError: undefined method `find_it' for #<struct xJob xxxx_id=527>>

I have a controller, which creates a delayed_job as follows, at the end of the controller method:

xJob.new(@xxxx.id).perform

Then in /lib/xJob.rb:

class xJob < Struct.new(:xxxx_id)

  include ActionView::Helpers

  def perform

    begin
     .......
     goodstuff  =  find_it(stuff)
     .......
    rescue Exception => e
     .....
    end
  end

  def self.find_it(body)
    ....
  end

end

I needed to add the self to self.find_it otherwise it I couldn't test that method in rspec. But now it seems to be breaking outside of RSPEC.

Ideas? Thanks

Upvotes: 0

Views: 942

Answers (1)

Rishav Rastogi
Rishav Rastogi

Reputation: 15492

Just remove the "self" from the find_it method declaration. Because its when you define it like that it becomes a class method of xJob, instead of a instance method.

Upvotes: 2

Related Questions