0

我仍在学习 Ruby(所以我是一个完整的菜鸟),现在我的应用程序在本地成功运行,但是当我尝试在 heroku 上打开应用程序时,我第一次执行时heroku run rake db:migrate偶然发现了一个问题......它告诉我:

Running `rake db:migrate` attached to terminal... up, run.2149
-- attr_accessible(:pName, :pQuantity, :pMeter, :pWeight, :pSellPrice,  :pCategory, :pPic)
-- attr_accessible(:pName, :pQuantity, :pMeter, :pWeight, :pSellPrice, :pCategory, :pPic)
rake aborted!
NoMethodError: undefined method `attr_accessible' for #<ActiveRecord::Migration:0x007f2dc2ba45b8>
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:648:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:641:in `method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:406:in `method_missing'
/app/db/migrate/20150802134246_create_inventories.rb:2:in `<class:CreateInventories>'
/app/db/migrate/20150802134246_create_inventories.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:761:in `load_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:757:in `migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:752:in `disable_ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:1044:in `use_transaction?'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:954:in `rescue in block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:951:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate

我一直在试图找出原因,在想了想之后我发现 rails 4.0.0 的变化不再使用 attr_accessible 而我们应该使用强参数,所以从模型中删除 attr_accessible 将解决问题.. .

但是,我有一个空模型,我看的任何地方都没有 attr_accessible。(除了这很奇怪,为什么我的应用程序在本地运行但不在 Heroku 上运行?)我无法弄清楚为什么会出现此错误以及在哪里寻找解决方案。我一直在尝试查看 active_record 文件,但害怕做出任何更改, 任何想法?

另外,谁能告诉我任何可以帮助我阅读此类日志错误的资源?我试图阅读一些文章,但找不到像我这样的菜鸟容易理解的文章...... ;(

4

1 回答 1

0

很高兴我能帮上忙 :)

就阅读日志错误而言,这就是我所做的。你会得到一堆关于你从未接触过的文件的行。这是因为尽管编写的内容很可能存在错误,但该错误会传播到整个 Rails 框架。这就是 Rails 非常酷的原因:它为你做了很多事情,所以你不必担心它们。

如果错误出现在您编写的代码中,则该文件也应该列在堆栈跟踪中。所以在这个例子中,你有一堆/app/vendor/bundle/...(我假设你没有碰过),但是有一个/app/db/migrate/...(很可能是你创建的)。

这使我认为错误在该文件中。另外,它甚至会为您提供行号(这:2就是 in 中的内容create_inventories.rb:2)。当然,这些行号并不总是正确的,但它应该让你从正确的地方开始!

于 2015-08-05T14:36:32.883 回答