简体   繁体   English

Rails错误500,“我们很抱歉,但出了点问题”

[英]Rails error 500, “We're sorry, but something went wrong”

After three evenings on this problem and reading all the posts about this, I have to ask this question finally! 经过三个晚上关于这个问题和阅读所有关于这个的帖子,我不得不最后问这个问题!

I want to deploy the most simple Rails app to Heroku: 我想将最简单的Rails应用程序部署到Heroku:

rails new test_appli
cd test_appli
git init
git add .
git  commit -m "initial commit"
heroku create
git push heroku master

Everything's OK, the application works well on Heroku. 一切都很好,该应用程序在Heroku上运行良好。 After that, I'll create a SQLite3 database: 之后,我将创建一个SQLite3数据库:

rails generate scaffold User name:string email:string
rake db:migrate

Everything's OK on the local machine. 本地机器上的一切都可以。 I can see localhost:3000/users well. 我可以看到localhost:3000/users Then I want to put the DB on Heroku. 然后我想将数据库放在Heroku上。 First I modify my Gemfile: 首先我修改我的Gemfile:

group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end

Then I send the whole thing to Heroku: 然后我将整件事发送给Heroku:

git init
git add .
git  commit -m "with Database"
git push heroku master
heroku rake db:migrate

Then there are no errors in the batch, everything is OK, the DB is sent, but the page heroku.com/users gives the error 然后批处理中没有错误,一切正常,数据库已发送,但页面heroku.com/users给出了错误

Rails 500, "We're sorry, but something went wrong" Rails 500,“我们很抱歉,但出了点问题”

I don't know more what to do. 我不知道该怎么做。 Can you help me? 你能帮助我吗?

I suspect you're trying to deploy a Rails 3.1 application to the bamboo stack (heroku create defaults to the 1.9.2 bamboo stack and doesn't run Rails 3.1 out of the box.). 我怀疑你正试图将一个Rails 3.1应用程序部署到竹栈(heroku创建默认为1.9.2竹栈并且不开箱即用Rails 3.1)。 The Cedar stack is much better suited to Rails 3.1 sites - Cedar堆栈更适合Rails 3.1站点 -

try 尝试

heroku create --stack cedar

when creating your application on Heroku and repush it up. 在Heroku上创建应用程序并重新注册时。 Also note your rake command on Heroku will become 还要注意你在Heroku上的rake命令会变成

heroku run rake db:migrate

Do: 做:

heroku run rake db:schema:load heroku运行rake db:schema:load

I had the same issue. 我遇到过同样的问题。 It works for me after git push heroku master 在git push heroku master之后它对我有用

Hey @redronin thanks for helping me find a way to connect to my postgres database on Heroku, however as a newbie to Heroku and postgresql I had to reverse engineer what "blah" was. 嘿@redronin谢谢你帮我找到一种方法连接我在Heroku上的postgres数据库,但作为Heroku和postgresql的新手,我不得不对“blah”进行逆向工程。 So I figure I would break it down to help others as you helped me. 所以我想我会在你帮助我的时候打破它来帮助别人。

postgres://[user]:[password]@[servername].compute-1.amazonaws.com/[database] postgres的:// [用户]:[口令] @ [服务器] .compute-1.amazonaws.com / [数据库]

Don't do the git init in the second set of commands - you only need to initialise your Git repo once. 不要在第二组命令中执行git init - 您只需要初始化一次Git repo。

Other than that this looks fine - are you seeing any errors anywhere? 除此之外这看起来很好 - 你在任何地方看到任何错误?

Why would you use the pg gem in your production group, but the sqlite3 gem in your development group? 为什么要在生产组中使用pg gem,而在开发组中使用sqlite3 gem? Seems to me that your problem is likely due to the fact that you're developing with a different database then you're using in the production environment. 在我看来,您的问题可能是由于您正在使用不同的数据库进行开发,然后您在生产环境中使用。 If I were you, I would stick to one, which would make it much easier to debug. 如果我是你,我会坚持一个,这将使调试更容易。

If you really want/need to get the application running ASAP, then just run it in production with sqlite... Gemfile: 如果你真的想/需要让应用程序尽快运行,那么只需在生产中使用sqlite运行它... Gemfile:

gem 'rails'
gem 'sqlite3'

Also, a quick way to figure out what the error is would be to run heroku logs from the unix console. 此外,快速找出错误的方法是从unix控制台运行heroku logs

Which version of Rails? 哪个版本的Rails? Can you try creating the application running on the Cedar stack? 您可以尝试创建在Cedar堆栈上运行的应用程序吗?

heroku create myapp --stack cedar

Given the application is running on cedar you need to modify the commands a bit, for example: 鉴于应用程序在雪松上运行,您需要稍微修改一下命令,例如:

heroku run rake db:migrate

In any case you really need to checkout your logs, because your problem might not even be database related, but assets related. 在任何情况下,您确实需要签出日志,因为您的问题甚至可能与数据库无关,但与资产相关。

Do you have the heroku shared 5mb database instance added? 你是否添加了heroku共享5mb数据库实例? When you create your heroku app (on cedar) it doesn't necessarily create the database automatically. 当您创建heroku应用程序(在雪松上)时,它不一定会自动创建数据库。

airlift:projects  $ heroku create --stack cedar testapp9
Creating testapp9... done, stack is cedar
http://testapp9.herokuapp.com/ | git@heroku.com:testapp9.git

airlift:projects  $ heroku addons --app testapp9 
logging:basic
releases:basic

When you view your heroku config, you get nothing: 当您查看heroku配置时,您什么都得不到:

heroku config heroku配置

airlift:projects  $ heroku config --app testapp9
airlift:projects  $

To add a database: 要添加数据库:

heroku addons:add shared-database:5mb heroku addons:添加共享数据库:5mb

airlift:projects  $ heroku addons:add shared-database:5mb --app testapp9
-----> Adding shared-database:5mb to testapp9... done, v3 (free)
airlift:projects  $ heroku config
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
airlift:projects  $ heroku config --app testapp9
DATABASE_URL        => postgres://blah:blah@blah.compute-1.amazonaws.com/blah
SHARED_DATABASE_URL => postgres://blah:blah@blah.compute-1.amazonaws.com/blah
airlift:projects  $ 

Then you should be able migrate your db. 然后你应该能够迁移你的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM