在Heroku控制台中创建新模型时获取NoMethodError(nil:NilClass的未定义方法`name') [英] Getting NoMethodError (undefined method `name' for nil:NilClass) when creating a new model in Heroku console
问题描述
我只是推了一下Heroku,试着通过rails_admin添加一个模型来做一些测试。当我这样做时,我得到了一个通用的错误页面。
NoMethodError(未定义方法`name'为nil:NilClass)
<然后我打开heroku控制台,尝试手动添加模型,并在尝试保存时收到相同的消息。
NoMethodError:未定义方法`name'为nil:NilClass
以下是模型:
class Board< ActiveRecord :: Base
attr_accessible:name,:description
验证:name,:presence => true
validates:description,:presence => true
validates_uniqueness_of:name,:case_sensitive => false
$ b $ has_many:subject
scope:hidden,where(:is_hidden => true)
scope:visible,where(:is_hidden => false)
结束
任何想法可能会发生什么 - 或者从哪里开始寻找?
我进行了迁移,并且能够看到它识别模型,并且在控制台中工作时它是属性。
感谢!
我不确定推送更改并运行时Heroku是否存在延迟或其他问题db:migrate,但花了几个小时后,我回来了,跑了耙db:再次迁移,这似乎什么都没做,然后我试图再次创建模型,它没有任何问题的工作。
现在一切都很顺利,但我不能说我只需要等待更长的时间才能测试Heroku,或者再次运行迁移实际上是否做了些什么。
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!
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.
这篇关于在Heroku控制台中创建新模型时获取NoMethodError(nil:NilClass的未定义方法`name')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!