I just did a push to Heroku and tried doing some testing by adding a model through rails_admin. When I did that I got a generic error page. I went into the logs and noticed this message:
NoMethodError (undefined method `name' for nil:NilClass)
I then opened heroku console and tried adding the model manually and received the same message when trying to save.
NoMethodError: undefined method `name' for nil:NilClass
Here is the model:
class Board < ActiveRecord::Base
attr_accessible :name, :description
validates :name, :presence => true
validates :description, :presence => true
validates_uniqueness_of :name, :case_sensitive => false
has_many :subjects
scope :hidden, where(:is_hidden => true)
scope :visible, where(:is_hidden => false)
end
Any ideas what might be happening with this - or where to start looking?
I did the migration and was able to see that it recognized the model and it's attributes when working in the console.
Thanks!
This is a common Ruby error which indicates that the method or attribute for an object you are trying to call on an object has not been defined.
The Undefined method for nil:NILClass occurs when you attempt to use a formula on a blank datapill. This indicates that the datapill was not provided any value at runtime.
The undefined method is also called the NoMethodError exception, and it's the most common error within projects, according to The 2022 Airbrake Error Data Report. It occurs when a receiver (an object) receives a method that does not exist.
After being bitten by this issue twice, I asked heroku support team for the reason why it happens. And they replied:
"after running rake db:migrate, you have to restart your application so it can pick up the schema changes, since the schema info is cached during boot in production mode."
So always remember to restart heroku app by 'heroku restart' after running a new migration.
I'm not sure if there is a delay or something with Heroku when pushing changes out and running db:migrate but after spending a few hours out and about, I came back, ran rake db:migrate again, which appeared to do nothing and then I tried creating the model again and it worked without any problems.
So all seems well now, but I can't tell I just needed to wait longer before testing with Heroku - or whether running the migration again actually did something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With