vramon
vramon

Reputation: 596

Rails Error: undefined method `private_method_defined?' for nil:NilClass

I'm trying to create and save an object, but I keep getting the error:

undefined method `private_method_defined?' for nil:NilClass

I wrote some simple code to work out the bug. In the controller, the code looks like this:

def testtutor
     @t = Tutor.new
     @t.fname = 'Test'
end

The model is mostly blank:

class Tutor < ActiveRecord::Base
  belongs_to :branch
end

The error occurs at:

@t.fname = 'Test'

Any idea what could be going on? I have created and migrated a "tutors" table, and "fname" is one of the fields.

Thanks for the help!

Upvotes: 3

Views: 161

Answers (2)

RuNpiXelruN
RuNpiXelruN

Reputation: 1920

I'd go into the console and try creating an entry there. t = Tutor.new

Then type

t.valid?

If it says false type

t.errors.full_messages and it will print out exactly what the issues are

Hope that helps

Upvotes: 0

Santhosh
Santhosh

Reputation: 29124

This error occurs if any database column names conflict with rails.

I faced the same issue when I had a column called "class".

Renaming it will fix the issue.

Upvotes: 1

Related Questions