【问题标题】:How to get rails asset pipeline compile coffee script and scss file?如何获取 Rails 资产管道编译咖啡脚本和 scss 文件?
【发布时间】:2014-10-23 02:46:29
【问题描述】:

这可能以前被问过。我已经用一些解决方案搜索了堆栈溢出。我试图实现那些很少:)。我被困住了。请帮忙。我是 Rails 新手

我在 assts 文件夹中有几个 scss 文件,如下所示

assets
    javascript
       application.js
       create.js.coffee
       help.js.coffee
    images

    stylesheets
       application.css
       create.css.scss
       forms.css.scss
       help.css.scss

我需要在 ruby​​ 资产管道中编译这些文件,以便编译然后组合,以便显示我的网站上未显示的样式和脚本。

在 application.js 我有

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

在application.css中,我有

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree .
 *= require 'site'
*/

另外,在 production.db 我有

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true

请帮助编译。有什么想法吗?

【问题讨论】:

  • 您需要在项目文件夹上运行rake assets:precompile,您可以在本地或远程服务器中执行此操作,但在远程服务器中才是真正应该执行的地方,这是您的问题吗?
  • 我已经运行了.. 对我没有用
  • 你怎么知道的?你检查你的public/assets 文件夹了吗?当说它不起作用时,请尝试更具体。
  • 是的,在公共资产文件夹中有两个空文件 application.css 和 application.js...
  • 然后它之前工作过,为了它重新生成文件,我通常使用rm -rf public/assets && rake assets:precompile

标签: css ruby-on-rails ruby asset-pipeline


【解决方案1】:

您必须在资产预编译之前设置 RAILS_ENV 值,因为默认情况下 RAILS_ENV 等于“开发”,但您需要设置“生产”。试试这个:

RAILS_ENV=production bundle exec rake assets:precompile

【讨论】:

    猜你喜欢
    • 2013-09-07
    • 2013-08-26
    • 2013-04-24
    • 2013-01-09
    • 2013-04-28
    • 2012-06-07
    • 2014-12-12
    • 2016-02-09
    • 1970-01-01
    相关资源
    最近更新 更多