Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database Heroku和Rails问题;数据库未在生产模式下工作_Database_Heroku_Ruby On Rails 4 - Fatal编程技术网

Database Heroku和Rails问题;数据库未在生产模式下工作

Database Heroku和Rails问题;数据库未在生产模式下工作,database,heroku,ruby-on-rails-4,Database,Heroku,Ruby On Rails 4,将我的应用程序部署到Heroku时出现问题。该页面在本地模式(localhost:3000)下运行完美,但当我与heroku访问同一页面时,我得到一个“很抱歉,但出了问题。”错误 heroku日志说明如下: ActionView::Template::Error(nil:NilClass的未定义方法“name”) 控制器中的代码: def week @bestbuy = Retailer.find_by(name: "bestbuy") end routes.rb中的代码: match '

将我的应用程序部署到Heroku时出现问题。该页面在本地模式(localhost:3000)下运行完美,但当我与heroku访问同一页面时,我得到一个“很抱歉,但出了问题。”错误

heroku日志说明如下:

ActionView::Template::Error(nil:NilClass的未定义方法“name”)

控制器中的代码:

def week
  @bestbuy = Retailer.find_by(name: "bestbuy")
end
routes.rb中的代码:

match '/week', to: 'static_pages#week', via: 'get'
视图中的代码:

<%= @bestbuy.name.upcase %>
我的gem文件中确实有gem“rails\u 12factor”


谢谢你的帮助。谢谢

如果没有找到符合条件的记录(),
find_by
方法将返回
nil
。在这种情况下,生产数据库似乎不包含名为“bestbuy”的零售商


我将通过直接查看数据库来调试它,以检查它是否包含您期望的数据(请参阅如何使用Heroku执行此操作)。

数据从您的应用程序中的何处来。你有没有植入你的应用程序数据?我昨天植入了我的应用程序数据,并将所有内容推送到Heroku,但得到了相同的错误。我又试了一次,一切都很好!不知道是什么改变了…谢谢!非常感谢。问题确实出在数据库上。我植入了我的应用程序,现在一切都正常了。
git commit -a -m "message"
git push heroku
heroku run rake db:migrate
heroku restart
heroku open