在使用Heroku部署我的应用程序Rails 4后,我遇到了一些问题。 该应用程序在开发中非常有效,但它在生产中并不完全有效。某些页面不显示(显示)=白页,特别是对于具有数据库的页面。我认为我有一些Sqlite3和/或postgresql的问题,但我不必解决问题。请帮帮我。
的Gemfile
source 'https://rubygems.org'
ruby '2.2.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
#modifie
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Use SCSS for stylesheets
#gem 'sass-rails', '~> 4.0.3'
gem 'sass-rails', '~> 5.0', '>= 5.0.4'
# 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', '~> 2.3', '>= 2.3.2'
#modifie
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', require: false
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-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
# gem ajoutés
gem 'rails-i18n', '~> 4.0', '>= 4.0.6'
gem 'simple_form', '~> 3.2'
gem 'country-select', '~> 1.1', '>= 1.1.1'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.5.1'
gem 'cucumber-rails', :require => false
gem 'cucumber', '~> 2.1'
#gem 'bcrypt-ruby', '~> 3.1', '>= 3.1.5'
gem 'bcrypt', '~> 3.1', '>= 3.1.10'
gem 'devise', '~> 3.5', '>= 3.5.2'
gem 'paperclip'
gem 'builder'
# group :production do
# #use PostgreSQL as the database for Active Record
# gem 'pg', '~> 0.18.4'
# end
group :production do
gem 'rails_12factor' # Heroku
end
group :test, :development do
# RSpec
gem 'rspec-rails', ">= 2.0.0.beta"
gem 'rspec', '~> 3.3'
gem 'factory_girl_rails', '~> 4.5'
gem 'capybara', '~> 2.5'
gem 'email_spec', '~> 1.6'
end
CONFIG / ENVIRONMENTS / DEVELOPMENT.RB
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
#For paperclip
Paperclip.options[:command_path] = "/usr/bin/"
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
#For devise
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Mailer GMail
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'XXXXXXX@gmail.com',
password: 'XXXXXX',
authentication: 'plain',
enable_starttls_auto: true }
end
CONFIG / ENVIRONMENTS / PRODUCTION.RB
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
#For devise
config.action_mailer.default_url_options = { :host => "http://library-online-duofer.herokuapp.com/" }
# Mailer GMail
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: 'XXXXX@gmail.com',
password: 'XXXXX',
authentication: 'plain',
enable_starttls_auto: true }
end
CONFIG / ENVIRONMENTS / TEST.RB
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
答案 0 :(得分:0)
在将应用程序部署到Heroku时,您是否完成了以下步骤...!
git push heroku master
heroku run rake db:migrate
有关将应用程序部署到Heroku的更多信息,请点击以下链接: Put Your App Online With Heroku
你必须预编译资产,使你的资产文件夹中的本地文件能够在Heroku应用程序中运行,因为Heroku不会自动为资产文件夹执行此操作,有关此过程的更多信息,请参阅给定的波纹管堆栈溢出线程。
How to load local images in Rail App to Heroku Production App
答案 1 :(得分:0)
看来,当我输入:git push heroku master
root@duong-SVE1513B1EW:~/Documents/Ruby_On_Rails# git push heroku master
Counting objects: 14, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.16 KiB | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/ruby
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.3
remote: ###### WARNING:
remote: Removing `Gemfile.lock` because it was generated on Windows.
remote: Bundler will do a full resolve so native gems are handled properly.
remote: This may result in unexpected gem versions being used in your app.
remote: In rare occasions Bundler may not be able to resolve your dependencies at all.
remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: -----> Installing dependencies using bundler 1.9.7
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
remote: Fetching gem metadata from https://rubygems.org/...........
remote: Fetching version metadata from https://rubygems.org/...
remote: Fetching dependency metadata from https://rubygems.org/..
remote: Resolving dependencies.....
remote: Using rake 10.4.2
remote: Using i18n 0.7.0
remote: Using json 1.8.3
remote: Using minitest 5.8.3
remote: Using thread_safe 0.3.5
remote: Using builder 3.2.2
remote: Using erubis 2.7.0
remote: Using rack 1.5.5
remote: Using mime-types 2.99
remote: Using arel 5.0.1.20140414130214
remote: Using execjs 2.6.0
remote: Using bcrypt 3.1.10
remote: Using sass 3.4.20
remote: Using bundler 1.9.7
remote: Using mini_portile2 2.0.0
remote: Using coffee-script-source 1.10.0
remote: Using thor 0.19.1
remote: Using concurrent-ruby 1.0.0
remote: Using country-select 1.1.1
remote: Using gherkin3 3.1.2
remote: Using diff-lcs 1.2.5
remote: Using multi_json 1.11.2
remote: Using multi_test 0.1.2
remote: Using orm_adapter 0.5.0
remote: Using mimemagic 0.3.0
remote: Using pg 0.18.4
remote: Using rails_serve_static_assets 0.0.4
remote: Using rails_stdout_logging 0.0.4
remote: Using tilt 2.0.1
remote: Using rdoc 4.2.1
remote: Using tzinfo 1.2.2
remote: Using mail 2.6.3
remote: Using rack-test 0.6.3
remote: Using warden 1.2.4
remote: Using autoprefixer-rails 6.2.2
remote: Using uglifier 2.7.2
remote: Using nokogiri 1.6.7.1
remote: Using coffee-script 2.4.1
remote: Using sprockets 3.5.2
remote: Using cucumber-core 1.3.1
remote: Using rails_12factor 0.0.3
remote: Using activesupport 4.1.8
remote: Using sdoc 0.4.1
remote: Using bootstrap-sass 3.3.6
remote: Using xpath 2.0.0
remote: Using cucumber 2.1.0
remote: Using actionview 4.1.8
remote: Using activemodel 4.1.8
remote: Using climate_control 0.0.3
remote: Using jbuilder 2.4.0
remote: Using capybara 2.5.0
remote: Using actionpack 4.1.8
remote: Using activerecord 4.1.8
remote: Using cocaine 0.5.8
remote: Using actionmailer 4.1.8
remote: Using railties 4.1.8
remote: Using sprockets-rails 2.3.3
remote: Using simple_form 3.2.1
remote: Using paperclip 4.3.2
remote: Using coffee-rails 4.0.1
remote: Using responders 1.1.2
remote: Using jquery-rails 3.1.4
remote: Using rails-i18n 4.0.8
remote: Using rails 4.1.8
remote: Using sass-rails 5.0.4
remote: Using turbolinks 2.5.3
remote: Using devise 3.5.3
remote: Using cucumber-rails 1.4.0
remote: Bundle complete! 27 Gemfile dependencies, 68 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: Bundle completed (3.99s)
remote: Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: Asset precompilation completed (1.77s)
remote: Cleaning assets
remote: Running: rake assets:clean
remote:
remote: ###### WARNING:
remote: Removing `Gemfile.lock` because it was generated on Windows.
remote: Bundler will do a full resolve so native gems are handled properly.
remote: This may result in unexpected gem versions being used in your app.
remote: In rare occasions Bundler may not be able to resolve your dependencies at all.
remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: ###### WARNING:
remote: No Procfile detected, using the default web server (webrick)
remote: https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing... done, 37.4MB
remote: -----> Launching... done, v38
remote: https://library-online-duofer.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
答案 2 :(得分:0)
我不知道你是否已经完成了整个过程,所以我觉得详细说明不会有什么坏处:
在Heroku上创建新应用后,您应该在资源中添加Postgres Add-on。它将创建一个名为DATABASE_URL
的环境变量,您可以在settings/config variables
中找到该变量。您应该在database.yml
中添加此变量的名称,如下所示:
production:
<<: *default
database: DATABASE_URL
然后你会推送这个文件,运行heroku rake db:migrate
,你应该好好去。
值得一提的是,您的developerWorks上没有填充Heroku上的新数据库,所以换句话说,您将从一个空数据库开始。
答案 3 :(得分:0)
@FreedomBanana:这是BookController:
class BooksController < ApplicationController
before_action :set_book, only: [:show, :edit, :update, :destroy]
# GET /books/all
# GET /books/all.json
# GET /books/all.xml
def all
@books = Book.all
end
# GET /books/available
# GET /books/available.json
# GET /books/available.xml
def available
@books = Book.available
end
# GET /books/reserved
# GET /books/reserved.json
# GET /books/reserved.xml
def reserved
@books = Book.reserved
end
# GET /books/1
# GET /books/1.json
# GET /books/1.xml
def show
@comments = @book.comments
@comment = @book.comments.new
end
# GET /books/new
def new
@book = Book.new
end
# GET /books/1/edit
def edit
end
def reserve_it
@ref_book = params[:ref_book]
@book = Book.find(@ref_book)
@book.situation_id = 2
@book.save
redirect_to '/books/available', notice: I18n.t('books.reserved')
end
def render_it
@ref_book = params[:ref_book]
@book = Book.find(@ref_book)
@book.situation_id = 1
@book.save
redirect_to '/books/reserved', notice: I18n.t('books.rendered')
end
# def send_mail
# @me= 'duong.elisabeth@gmail.com'
# ContactMailer.contact_email(@me).deliver
# redirect_to '/contact', notice: I18n.t('Mail_sent')
# end
def delete
@ref_book = params[:ref_book]
@book = Book.find(@ref_book)
@book.destroy
redirect_to '/books/all', notice: I18n.t('books.destroyed')
end
# POST /books
# POST /books.json
def create
@book = Book.create(book_params)
@book.situation_id = 1
respond_to do |format|
if @book.save
format.html { redirect_to @book, notice: I18n.t('books.created') }
format.json { render :show, status: :created, location: @book }
else
format.html { render :new }
format.json { render json: @book.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /books/1
# PATCH/PUT /books/1.json
def update
respond_to do |format|
if @book.update(book_params)
format.html { redirect_to @book, notice: I18n.t('books.updated') }
format.json { render :show, status: :ok, location: @book }
else
format.html { render :edit }
format.json { render json: @book.errors, status: :unprocessable_entity }
end
end
end
# DELETE /books/1
# DELETE /books/1.json
def destroy
@book.destroy
respond_to do |format|
format.html { redirect_to books_url, notice: I18n.t('books.destroyed') }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_book
@book = Book.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def book_params
params.require(:book).permit(:title, :author, :synopsis, :cover, :note, :situation_id)
end
end
答案 4 :(得分:0)
我不知道为什么,但我成功地解决了这个问题。
我只需将production.rb
行更改为config.action_controller.perform_caching = true
到config.action_controller.perform_caching = false
我不明智,但现在有效。 谢谢大家的帮助