Johnny Brofish
Johnny Brofish

Reputation: 115

Rails: nil error class not found

My code cannot find the module and returns an nil error.

undefined method `next' for nil:NilClass

Here is code

module Test
  class MyTestClass

    before_save :cid

    def cid
      MyTestClass.maximum(:id).next #error here, can't find MyTestClass 
    end
end

I tried variants like Test::MyTestClass but none worked.

Upvotes: 0

Views: 74

Answers (3)

Akshay
Akshay

Reputation: 830

You don't need to use MyTestClass inside the method 'cid'.

You can just use:

module Test
  class MyTestClass

    before_save :cid

    def cid
      self.maximum(:id).next
    end
  end // End of class
end

Upvotes: 1

Don Lee
Don Lee

Reputation: 463

MyTestClass.maximum(:id).next
-> self.maximum(:id).next

Upvotes: 0

adamliesko
adamliesko

Reputation: 1915

In that context, you can safely use maximum(:id).next

Upvotes: 0

Related Questions