質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Q&A

解決済

1回答

319閲覧

Railsアプリをherokuでデプロイしたら画像が表示されず、エラーが出ます。

m.shinji

総合スコア20

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

2グッド

2クリップ

投稿2019/01/25 12:09

編集2019/01/27 04:24

ruby on rails5で開発しており、herokuでデプロイしようとしたところ、普通に画面は開けるのですが、画像が全て表示されませんでした。

$ git push heroku masterをしたところ下記のようなエラーが出てしまいました。

terminal

1remote: ! 2remote: ! Could not detect rake tasks 3remote: ! ensure you can run `$ bundle exec rake -P` against your app 4remote: ! and using the production group of your Gemfile. 5remote: ! rake aborted! 6remote: ! NameError: undefined local variable or method `config' for main:Object 7remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/config/application.rb:21:in `<top (required)>' 8remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/Rakefile:4:in `require_relative' 9remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/Rakefile:4:in `<top (required)>' 10remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load' 11remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load_rakefile' 12remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:703:in `raw_load_rakefile' 13remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:104:in `block in load_rakefile' 14remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling' 15remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:103:in `load_rakefile' 16remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:82:in `block in run' 17remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling' 18remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/lib/rake/application.rb:80:in `run' 19remote: ! /tmp/build_748fc6249664ecd98651a7605debdef3/vendor/bundle/ruby/2.4.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>' 20remote: ! vendor/bundle/bin/rake:17:in `load' 21remote: ! vendor/bundle/bin/rake:17:in `<main>' 22remote: ! 23remote: /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)

試したこと

confing/environments/production.rbで
・config.assets.compile = true
・config.serve_static_assets = true
置き換えました。

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 # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # 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 = true config.serve_static_assets = true # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # 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 # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = :local # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "dateplan_#{Rails.env}" config.action_mailer.perform_caching = false # 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 # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end

confing/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 Dateplan 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. end end config.assets.initialize_on_precompile = false

初めてのデプロイで、様々なサイトを参考にしましたが、どう解決すれば良いのかわかりません。どなたか、教えていただけると助かります!!!

DrqYuto, set0gut1👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

confing/application.rbの中の
config.assets.initialize_on_precompile = false
がいらなかったようです。

以下は、自分への今後の教訓です。
「Nameerrorが出た際は、rubyの変数スコープを確認する。」

投稿2019/01/29 15:24

m.shinji

総合スコア20

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問