LoginSignup
3
0

More than 5 years have passed since last update.

rails s したときになぜかCSSファイルが表示されない

Posted at

先日、新しいvagrant環境に社内環境をgit cloneし、いろいろ整えたのち、いざ rails s と叩いたら、、、
なぜかCSSファイルが読み込まれない、、、

DBに問題があるのかと思い、db create:resetしたら環境が壊れかける始末。

巡り巡って見つけた原因、
それはconfig/environment/development.rbにありました。

config/environment/development.rb
Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # 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.
  config.consider_all_requests_local = true

  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
    }
  else
    config.action_controller.perform_caching = false

    config.cache_store = :null_store
  end

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.perform_caching = 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

  # Suppress logger output for asset requests.
  config.assets.quiet = true

  # 引き継ぎ設定
  config.assets.raise_runtime_errors = true
  config.action_controller.asset_host = 'localhost:3000'
  config.action_mailer.asset_host = config.action_controller.asset_host

  # For send mail on ubuntu
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

  config.logger = Logger.new("log/development.log", 5, 10 * 1024 * 1024)

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

真ん中あたりの、 #引き続き設定 の項目に注目です。
ここでhostのipアドレスは localhost:3000 となっています。

しかし、vagrant本体で、Vagrantfileで指定していたprivate networkのipアドレスを見たところ、 http://192.168.33.10 でした。

ここが一致していないのが原因でした…。

ここを本体のipアドレスに書きかえたところ、無事にCSSファイルが読み込まれるようになりました。
めでたしめでたし。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0