【问题标题】:How do I tell compass this Rails' environment is a development one?我如何告诉罗盘这个 Rails 的环境是开发环境?
【发布时间】:2012-01-22 13:45:51
【问题描述】:

我正在使用 Ruby On Rails (v. 3.0.10) 并使用 Compass (0.11.5)。

我正在使用两个开发环境:

  1. 标准 Rails 的 development 环境,在连接到 PostgreSQL 数据库的 config/environments/development.rb 中定义。

  2. config/environments/dev-sqlite.rb 中定义的开发环境dev-sqlite 的副本,唯一的区别是附加的数据库(这次是本地SQLite,当我在运行时无法访问我的开发数据库服务器)。

Compass 的问题是,当我在 dev-sqlite 环境中运行 Rails 时(在运行任何 Rails 命令之前使用 RAILS_ENV='dev-sqlite'Compass 似乎在生产模式下工作,它不会重新生成我的 CSS更改 SCSS 文件时的文件,就像我在 development 环境中所做的那样。这使我的开发工作更加困难......

我尝试将此行添加到config/compass.rb 文件并重新启动我的本地Rails 服务器(使用rails s),但没有成功:

environment = :development if Rails.env == 'dev-sqlite'

事实上,即使environment = :development 也不会改变任何事情。

提前感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails development-environment compass-sass


    【解决方案1】:

    我在配置文件的底部添加了以下内容,这对我来说效果很好:

    # Enable Debugging (Line Comments, FireSass)
    # Invoke from command line: compass watch -e development --force
    if environment == :development 
      output_style = :expanded
      sass_options = {:debug_info => true}
    end
    

    然后你只需要在运行 compass watch (或编译)时指定你是在开发环境中。您可以通过运行compass watch -e development --force 来执行此操作。正如你所看到的,我把它放在我的配置文件的注释中,以防我忘记了。

    另外,请务必在 chrome 开发者工具中启用 sass 以利用 sass 源映射

    【讨论】:

    • 感谢您的回答!已经有一段时间了,所以我的项目发生了很大变化,我还没有用,但如果再次发生这种情况,我一定会检查你的提示。
    猜你喜欢
    • 1970-01-01
    • 2013-10-25
    • 2014-07-25
    • 2018-10-20
    • 2011-11-21
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多