【问题标题】:Rails works fine locally but not in herokuRails 在本地运行良好,但在 heroku 中却不行
【发布时间】:2013-02-13 09:46:32
【问题描述】:

我为 root 创建了一个自定义页面,并在 routes.rb 中进行了相应更改。我在使用 git 之前删除了 public/index.html 文件,但应用程序仍在 heroku 中查找 public/index.html 文件。该应用程序有效在本地很好,但问题是在 heroku 中部署时。请提出一些解决方案?我的 Gemfile 包含

source 'https://rubygems.org'
gem 'rails', '3.2.11'
group :development do
  gem 'sqlite3', '1.3.5'
end
group :assets do
  gem 'sass-rails','3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end
gem 'jquery-rails'
gem 'thin'

我没有在我的应用程序中使用数据库。控制器只是对 json 字符串进行一些计算。

【问题讨论】:

  • 在推送到 heroku 之前,您是否已将更改提交到 git?您是否编辑了您的 routes.rb 并设置了 'root :to => "something" '?
  • 是的,但我仍然收到 500 错误
  • Heroku 日志在=info method=GET path=/ host=guarded-atoll-1158.herokuapp.com fwd=117.204.119.60 dyno=web.1 queue=0 wait=0ms connect 处显示此错误=7ms 服务=1583ms 状态=500 字节=643
  • 请在您的项目文件夹中发布“heroku 日志”的输出。

标签: ruby-on-rails heroku


【解决方案1】:

相信你已经用过:

git add .
git commit -m "blabla"

但是,git add . 不会查找已删除的文件,因此public/index.html 仍然存在。

您必须使用git add -u 来包含已删除的文件。

或者,你可以使用git add -A,相当于git add .加上git add -u

编辑 - 使用 cmets 一步一步:

git add -A                #add everything (including deleted files)
git commit -m "blabla"    #commit it
git push                  #push from your pc to your git repository
git push heroku           #push from your git repository to heroku

如果您删除了public/index.html 文件,它一定可以工作。

编辑将以下内容添加到您的 gemfile:

group :production do
  gem 'pg'
end

比:

RAILS_ENV=production bundle exec rake assets:precompile
git add -A
git commit -m "blabla"
git push
git push heroku

【讨论】:

  • 我已经编辑了我的答案,包括一步一步...我希望它有所帮助
  • Heroku 日志在=info method=GET path=/ host=guarded-atoll-1158.herokuapp.com fwd=117.204.119.60 dyno=web.1 queue=0 wait=0ms connect 处显示此错误=7ms 服务=1583ms 状态=500 字节=643
  • 我认为问题出在您的资产上。尝试运行RAILS_ENV=production bundle exec rake assets:precompile,而不是我的答案中的步骤,最后运行heroku rake db:migrate
  • 连接到由 DATABASE_URL 指定的数据库 rake 中止!请安装 postgresql 适配器:gem install activerecord-postgresql-adapter(pg 不是捆绑包的一部分。将其添加到 Gemfile。)
  • 您可以编辑问题以包含您的gemfile 吗?它可能缺少生产组内的gem 'pg'
猜你喜欢
  • 2013-09-22
  • 1970-01-01
  • 2019-02-11
  • 1970-01-01
  • 2018-04-10
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
相关资源
最近更新 更多