$ git push heroku masterすると以下のエラーが出ます。
NoMethodError: Cannot load database configuration:undefined method `[]' for nil:NilClass
$ RAILS_ENV=development bin/rails assets:precompileの結果
mart@shigeruuraguchimasatonoMacBook-Pro myblog02 % RAILS_ENV=development bin/rails assets:precompile yarn install v1.22.4 [1/4] ???? Resolving packages... success Already up-to-date. ✨ Done in 0.05s.
$ RAILS_ENV=production bin/rails assets:precompileの結果
mart@shigeruuraguchimasatonoMacBook-Pro myblog02 % RAILS_ENV=production bin/rails assets:precompile yarn install v1.22.4 [1/4] ???? Resolving packages... success Nothing to install. success Saved lockfile. ✨ Done in 0.05s. I, [2020-12-16T12:33:03.824189 #7543] INFO -- : Writing /Users/mart/myblog02/public/assets/application-f11ff91e826976101c0618dd53de0c322bf29547aa6eb5ef361086beae31a1d1.js I, [2020-12-16T12:33:03.824707 #7543] INFO -- : Writing /Users/mart/myblog02/public/assets/application-f11ff91e826976101c0618dd53de0c322bf29547aa6eb5ef361086beae31a1d1.js.gz I, [2020-12-16T12:33:13.127223 #7543] INFO -- : Writing /Users/mart/myblog02/public/assets/application-89ff2b0b13c65904beddb9cb1c007267d2121137ac074de709685c9d5e9bfe13.css I, [2020-12-16T12:33:13.127390 #7543] INFO -- : Writing /Users/mart/myblog02/public/assets/application-89ff2b0b13c65904beddb9cb1c007267d2121137ac074de709685c9d5e9bfe13.css.gz
- ruby 2.5.1
- rails 5.2.3
- postgresql
database.yml
# PostgreSQL. Versions 9.1 and up are supported. # # Install the pg driver: # gem install pg # On OS X with Homebrew: # gem install pg -- --with-pg-config=/usr/local/bin/pg_config # On OS X with MacPorts: # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: # gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. # # Configure Using Gemfile # gem 'pg' # default: &default adapter: postgresql encoding: unicode username: <%= Rails.application.credentials.db[:username] %> password: <%= Rails.application.credentials.db[:password] %> # host: localhost # For details on connection pooling, see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: myblog02_development # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. # When left blank, postgres will use the default role. This is # the same name as the operating system user that initialized the database. #username: myblog02 # The password associated with the postgres role (username). #password: # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. #host: localhost # The TCP port the server listens on. Defaults to 5432. # If your server runs on a different port number, change accordingly. #port: 5432 # Schema search path. The server defaults to $user,public #schema_search_path: myapp,sharedapp,public # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic # Defaults to warning. #min_messages: notice # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: myblog02_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: myblog02_production username: <%= ENV['DB_USER'] %> password: <%= ENV['DB_PASSWORD'] %>
apprication.scss
/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's * vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * *= require_tree . *= require_self */ @import "bulma"; @import "font-awesome-sprockets"; @import "font-awesome"; .notification:not(:last-child){ margin-bottom: 0; } .profile_image { border-radius: 50%; } #bg-video{ position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: -100; background: url('P_20181107_220321.jpg') no-repeat; background-size: cover; }
apprication.js
// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's // vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require rails-ujs //= require activestorage //= require turbolinks //= require jquery3 //= require_tree .
試したこと
1.database.ymlのproduction環境指定欄を削除
リンク内容
2.GitHubリポジトリ上で RAILS_MASTER_KEY を設定する
リンク内容
3.config>environments>production.rbの下記の通り編集
config.assets.js_compressor = :uglifier #これをコメントアウトする
4.config/application.rbにconfig.assets.initialize_on_precompile = falseを追加
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Myblog02 class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. config.time_zone = 'Tokyo' config.assets.initialize_on_precompile = false end end
当方、プログラミングを始めて半年の初学者です。
いろいろ試してみましたがうまくいきません。
どなたかご教授頂けないでしょうか。よろしくお願いします。
あなたの回答
tips
プレビュー