开发者

NoMethodError: undefined method - How to find a method?

开发者 https://www.devze.com 2023-02-17 23:16 出处:网络
I\'m getting the following error: #<NoMethodError: undefined method `find_it\' for #<struct xJob xxxx_id=527>>

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(b开发者_如何学Cody)
    ....
  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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消