Rails 4在更改时不会更新dev中的css

时间:2016-06-16 17:43:13

标签: ruby-on-rails asset-pipeline

我一直在努力解决这个问题,但基本上每当我对下面列出的css文件进行更改时(例如layout.scss),我必须停止服务器并运行{{ 1}}然后重新启动服务器,然后才能看到更改。

毋庸置疑,这非常乏味。下面是我的配置;如果您还有其他任何想要发布的内容,请告诉我。

的Gemfile

rake assets:clobber

development.rb

source 'https://rubygems.org'
ruby '2.2.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.2.5'

# DB Tools
  gem 'pg'
  gem 'money-rails'
  gem 'pluck_to_hash'

# View Development Tools
  gem 'sassc-rails'
  gem 'haml-rails'
  gem 'friendly_id', '~> 5.1.0'

# View Display Tools
  gem 'jquery-rails'
  gem 'font-awesome-rails'

# Form Tools
  gem "cocoon"
  gem 'amoeba'

# Angular Tools
  gem 'angularjs-rails', '~> 1.4.7'
  gem 'angular-rails-templates'
  gem 'angular_rails_csrf'

# API Tools
  gem 'active_model_serializers', '~> 0.10.0.rc2'
  gem 'easy_diff'

# Authentication / Authorization
  gem 'devise'

# Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '>= 1.3.0'
  gem 'sdoc', '~> 0.4.0', group: :doc

# Hosting, Serving & Deployment
  gem 'puma'
  gem 'foreman'

# Env specific
group :development do
  gem 'awesome_print', :require => 'ap'
  gem "better_errors"
  gem "binding_of_caller"
  gem 'annotate', '~> 2.6.6'
  gem 'seed_dump'
end

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

application.css

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = true

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.assets.debug = true
  config.assets.prefix = "/dev-assets"
  config.assets.digest = false
  config.serve_static_files = false

  config.assets.raise_runtime_errors = true

  config.sass.inline_source_maps = true

  config.action_mailer.default_url_options = { host: 'localhost', port: 8080 }

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    address:              "smtp.gmail.com",
    port:                 587,
    domain:               ENV["GMAIL_DOMAIN"],
    user_name:            ENV["GMAIL_USERNAME"],
    password:             ENV["GMAIL_PASSWORD"],
    authentication:       "plain",
    enable_starttls_auto: true
  }

end

应用loader.scss

/*
 *= require_self
 *= require application-loader
*/

2 个答案:

答案 0 :(得分:1)

在追回@gates在我原来回答的评论中提出的想法之后,我遇到了this blog post

基本上,由于sprockets没有进行加载,似乎没有重新编译单个文件的更改(虽然我不知道为什么整体重新编译没有更新),所以在博客的说明,我现在sprockets加载所有文件,我根据需要导入mixins。像这样:

<强> application.css

/*
 *= require_tree ./common
 *= require_tree ./authenticated
 *= require font-awesome
 *= require_self
*/

<强>认证/验证-layout.scss

@import '../flexbox.scss';
@import '../mixins.scss';

body {
  // etc...
}

我现在可以对我的任何scss文件进行更改并重新加载页面,而不必破坏资产和/或重新启动服务器!

答案 1 :(得分:0)

您认为我们需要在'initialisers / assets.rb'中添加文件吗?这对我有用了一次。