【发布时间】: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