0

I have some problem after deploying my application Rails 4 with Heroku. The application works very well in development, but it doesn't work totally in production. Some pages don't appear (Show) = white page, in particular for the pages which have a database. I think i have some problem with Sqlite3 and/or postgresql but i don't have to resolve the problem. Please help me.

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
Pulkit Agarwal
  • 594
  • 1
  • 9
  • 22
Joker
  • 33
  • 7

5 Answers5

0

Did you complete the following steps while deploying the app to Heroku...!

  1. git push heroku master
  2. heroku run rake db:migrate

For more on deploying an app to Heroku, follow the link: Put Your App Online With Heroku

You have to pre-compile the assets to make your local files in assets folder to get run in Heroku app, as Heroku wont do it automatically for the assets folder, for more on this process see the given bellow stack overflow thread.

How to load local images in Rail App to Heroku Production App

Community
  • 1
  • 1
Praveen George
  • 9,237
  • 4
  • 26
  • 53
  • Yes i do all correctly. This is the link to my app: library-online-duofer.herokuapp.com . When you have sign up, go to Books section --> All Books --> Show (it doesn't appears anything)/ Edit too – Joker Dec 29 '15 at 11:59
  • @Joker : How you are storing the book details into the application ? Your data inside your database containing book details in local app wont be available in the heroku app, you have to feed the data in production or you have to export your local database along with the data into Heroku. Did you do that ? – Praveen George Dec 29 '15 at 13:09
  • @Joker Please update your question with the Controller code above, possibly the error may due to error code in show/edit methods in your controller. – Praveen George Dec 29 '15 at 13:19
  • I don't understand very well what you say. When my app was deployed : library-online-duofer.herokuapp.com , i tried to add new data by creating a new book (with the form of the app). But it doesn't work, i have a white page after create the book – Joker Dec 29 '15 at 13:20
  • @Joker : Hey now check the app in your Heroku, everything is working fine now, create books, or update the books in production, you dont need to do anything more, already everything working fine in your Rails application. – Praveen George Dec 30 '15 at 04:18
  • Thanh you for your help Praveen George – Joker Dec 30 '15 at 11:57
0

It appears that when i type : 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.
Joker
  • 33
  • 7
0

I don't know if you've been through the whole process so I guess it won't hurt to detail it :

After you've created a new app on Heroku you should add Postgres Add-on in resources. It will create an environment variable named DATABASE_URL that you can find in settings/config variables. You should add this variable's name in your database.yml as follow :

production:
  <<: *default
  database: DATABASE_URL

Then you'll push this file, run heroku rake db:migrate, and you should be good to go. Worth saying your new database on Heroku won't be populate by your development.sqlite3, so in other words you'll start with an empty database.

theFreedomBanana
  • 2,462
  • 2
  • 22
  • 29
  • I did like you say i add Postgres Add-on in Heroku Toolbelt. It create an variable DATABASE_URL in settings/config/variables. And then i change the file database.yml like you say for the production section with database : DATABASE_URL . Then i push all with git push heroku master, and heroku run rake db:migrate but i always have the white page in the section Books/All Books/show of my app: library-online-duofer.herokuapp.com – Joker Dec 29 '15 at 13:15
  • if possible can you provide the github address of your project or the books_controller an books/show.html.erb – theFreedomBanana Dec 29 '15 at 14:10
  • @FreedomBanana : See the code BooksController beneath please – Joker Dec 29 '15 at 14:32
0

@FreedomBanana: It is the 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
Joker
  • 33
  • 7
  • I don't see nothing wrong in the way show method is defined, and since you've said it works in development it should work the same in production. I'm gonna state the obvious but I assume you've got a `show.html.erb` file within a books directory in the views. In the same fashion you must have a `books.html.erb` or at least an `application.html.erb` within views/layouts directory with a `<%= yield %>` in the body. Maybe you can do insert respond_with(@book) at the end of you show method. – theFreedomBanana Dec 29 '15 at 16:06
0

I don't know why but i succeed to resolve the problem.

I just change into the file production.rb the line: config.action_controller.perform_caching = trueto config.action_controller.perform_caching = false

I don't understant but it works now. Thank you all for your help

Joker
  • 33
  • 7