【问题标题】:RoR app: Problems deploying app to herokuRoR 应用程序:将应用程序部署到 heroku 时出现问题
【发布时间】:2014-11-25 10:59:59
【问题描述】:

我最近为我一直在开发的现有 rails 应用程序创建了一个 heroku 应用程序。我只有一个希望在浏览器上显示的 html 文件。该文件从我的数据库中获取新闻报道(从开发的角度来看,从技术上讲,sqlite3 应该可以工作。我已经让它与 railstutorial 一起使用,我根本没有配置 postgres),以及它们相应的图像,并吐出他们到页面。这在 localhost 上运行良好,但是当我使用“heroku open”进行部署时,我看到的只是一个空白页面,其中包含我在页面顶部添加的标题标签:“来自 BBC 的热门故事”。就好像应用程序根本不读取 eRB 标签一样。这是我的索引视图 html.erb 文件的代码:

<h1> Top stories from BBC <h1>


<% @stories.each do |story| %>

<% if story.image.nil? %>

<% # do nothing %>

<% else %>
<div> 
    <h3><%= story.name %></h3>
    <p><%= story.summary %></p>
    <a href = "<%= story.url %>" >
        <img src="<%= story.image %>" />
    </a>
</div>

<% end %>

<% end %>

这是我的 gemfile:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.8'

gem 'feedjira'

gem 'mechanize'

gem 'nokogiri'

# Use sqlite3 as the database for Active Record
group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
    gem 'pg', '0.15.1'
    gem 'rails_12factor', '0.0.2'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

我一直在使用 heroku 和 git 命令,例如:

  • git 推送
  • git push heroku
  • heroku 运行 rake db:migrate
  • rake 资产:预编译
  • git 添加。 /git 提交 -m/等。
  • git push heroku master

即使在多种不同的组合中尝试了上述方法后,似乎也没有任何效果。我会很感激你们提供的关于如何让我的索引页面在 Heroku 上正确呈现的任何反馈。它可以在本地主机上完美运行。

谢谢,我们将不胜感激!

【问题讨论】:

  • 我认为问题出在数据库上,要么你的数据库没有在 heroku 上配置,要么你的故事在 heroku 数据库上是空的
  • 你能告诉我们你的控制器吗?
  • 在config/environments/production.rb文件中,你改成这个config.serve_static_assets = true了吗?

标签: ruby-on-rails ruby git heroku


【解决方案1】:

您已将代码推送到 Heroku,但您的 Heroku 数据库为空。如果您的本地数据库中有您想要在 Heroku 上的数据,只需推送!

 heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi

地点:

mylocaldb 是您本地数据库的名称

HEROKU_POSTGRESQL_MAGENTA 是您的 Heroku 数据库的名称(从 heroku pg:info -a myapp 找到它)

重要提示:Heroku 使用 postgres,因此您也应该在本地使用 postgres。此处所述的许多命令都要求您在计算机上安装 postgres。

请务必通读 Heroku 提供的非常有用的帮助页面:https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull

【讨论】:

  • 谢谢,但请问我如何找到 mylocaldb 的名称?我现在已经安装了 postgreSQL 并且之前使用的是 sqlite3。非常感谢。
  • 检查您的 database.yml 文件。此外,如果您从 sqlite 迁移到 postgres,我使用 RailsCast 并点击:railscasts.com/episodes/…
猜你喜欢
  • 2017-01-26
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-18
  • 2022-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多