在rails 3.1中,.coffee和// = require文件只处理一次或每个资产请求吗?
例如,我有一个文件
//= require source/main.js.coffee
//= require source/second.js.coffee
//= require source/third.js.coffee
理想情况下,服务器会将这些编译为js ONCE,然后捆绑它们,然后创建一个静态文件.但如果它发生在每个资产请求上,它将浪费周期重复它?
感谢您的任何指导.
javascript ruby-on-rails coffeescript ruby-on-rails-3.1 asset-pipeline
我将服务器切换到生产状态,我无法加载任何图像.这一切都在开发模式下工作正常但是当我切换到生产时它都停止工作我启用了server_static_assets但仍然无效.这样做的任何帮助
运行资产时:预编译rake任务,会创建应用程序资产的gzip压缩版本.根据资产管道的Rails指南,您可以配置Web服务器(在我的情况下是Apache 2.2)来提供这些预压缩文件,而不是让Web服务器完成工作.
我无法弄清楚的是如何配置mod_deflate以便提供这些文件而不是双重压缩然后提供?
我通过httpd.conf启用了mod_deflate:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Run Code Online (Sandbox Code Playgroud)
我已经将rails指南上的代码转换为公共/资产中的.htaccess:
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
Header unset Last-Modified
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
# Serve gzipped versions …Run Code Online (Sandbox Code Playgroud) 我们正在开发一个非常广泛的应用程序.该网站将有许多不同的部分,具有一些非常不同的用户界面要求和行为.
展望未来,Rails 4将资产管道分离为一个独立的宝石,以便我们可以选择是否包含它.turbolinks可能会发生同样的事情.
这些天我一直在问自己并且找不到答案的问题是:我应该在我们的项目中使用这些库吗?
我反思的主要问题是,一体化文件策略可能不起作用,我们将不得不在应用程序的不同部分使用文件包.turbolink会如何对此作出反应,因为它必须假设所有js/css已经加载?这种配置的优势是否克服了管道和turbolinks所隐含的代码复杂性?
我不指望是/否答案,只是对此事的一些看法.
ruby ruby-on-rails asset-pipeline turbolinks ruby-on-rails-4
在我的一个Rails应用程序中,ExecJS没有显示coffeescript编译错误的行号.我的编译错误消息将如下所示:
ExecJS::RuntimeError in Referrals#new
Showing ~/MyApp/app/views/layouts/application.html.erb where line #6 raised:
SyntaxError: unexpected IDENTIFIER
(in ~/MyApp/assets/javascripts/utils.js.coffee)
Run Code Online (Sandbox Code Playgroud)
请注意,咖啡脚本源没有行号(第6行用于erb文件).
在我的另一个应用程序中,我仍然在获取行号,语法错误如下所示:
ExecJS::ProgramError in Projects#show
Showing ~/OtherApp/app/views/layouts/application.html.erb where line #17 raised:
Error: Parse error on line 6: Unexpected 'STRING'
(in ~/OtherApp/app/assets/javascripts/projects.js.coffee)
Run Code Online (Sandbox Code Playgroud)
所以看起来不同的是,它ExecJS::ProgramError会给出行号,而ExecJS::RuntimeError不是.
任何人都知道如何获得行号?为什么我的应用程序在咖啡资产编译时创建RuntimeErrors,而另一个是给出ProgramErrors?我检查过Rails,它们似乎匹配.
请注意,如果我修复编译错误,应用程序运行正常(例如,咖啡文件实际上已经编译) - 但是让这些行号指向编译错误会很好!
编辑
我意识到无论是ExecJS Runtimeerror还是ProgramError似乎并不重要 - 在第一个应用程序中,从来没有给出行号,而在第二个应用程序中,总是有.
在Rails 3中有一个rake资产:预编译:nodigest任务,它编译资产并在/ public/assets目录中编写没有摘要部分的资源.在Rails 4中,这已被删除,默认情况下,所有资产都只使用摘要进行预编译.由于各种原因,我还需要一些资产的非消化版本.有没有简单的方法来启用旧的行为?
我的rails应用程序有问题(Rails 4.0.0.rc2,ruby 2.0.0p195).
行为很奇怪:我的localhost正确显示背景图片,Heroku没有.
在heroku日志中,我可以看到以下错误:
ActionController::RoutingError (No route matches [GET] "/assets/piano.jpg"):
Run Code Online (Sandbox Code Playgroud)
我通过在custom.css.scss中插入以下代码来创建背景图像:
.full {
background: image-url("piano.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)
我用以下代码触发了这个,我在静态页面上有这个代码:
<body class="full">
....
</body>
Run Code Online (Sandbox Code Playgroud)
我已经在生产中运行了宝石:
group :production do
gem 'pg'
gem 'rails_12factor'
end
Run Code Online (Sandbox Code Playgroud)
在production.rb中,我将以下设置设置为true:
config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)
但是,图像未显示.你能帮我吗?
请帮我理解究竟heroku run rake assets:precompile是什么.自从我开始在rails上使用ruby之后,我总是在推送到github和heroku之前运行这三个命令:
bundle exec rake assets:precompile
RAILS_ENV=production bundle exec rake assets:precompile
在我推到heroku后,我会跑:
heroku run rake assets:precompile
但是,当我在上次推送到heroku后尝试运行它时,我在不同的文件上遇到了一堆相同的错误.例如:
Warning. Error encountered while saving cache ... can't dump anonymous class ...
为了看看我能解决这个问题,我跑了
heroku run rake assets:clean再heroku run rake assets:precompile一次.问题是一切都运转正常,但我觉得如果有这些警告/错误.请帮我理解.谢谢!
我试图从application.js单独创建一个自定义清单javascript文件.我从application.js获取代码并将其粘贴到我称为"other_manifest.js"的新文件中,并放在assets/javascrips目录中.这是代码:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about …Run Code Online (Sandbox Code Playgroud) ruby-on-rails sprockets asset-pipeline ruby-on-rails-4 ruby-on-rails-4.1
在Rails 3.2.11应用程序中,我正在尝试将我的应用程序发布到Heroku.
在assets文件夹中,我有一个pdf子文件夹,里面有一些pdf文件.
在我的production.rb文件中,我添加了以下内容:
config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif *.pdf]
config.assets.precompile += ["*.js"]
config.assets.precompile += ["*.css"]
config.assets.precompile += ['pdf/*']
config.assets.precompile += %w( ricerca_wg.pdf )
Run Code Online (Sandbox Code Playgroud)
如果我检查控制台上的pdf资产路径,我会得到:
Rails.application.config.assets.paths
# [
# "/Users/Augusto/Sites/wisegrowth/app/assets/images",
# "/Users/Augusto/Sites/wisegrowth/app/assets/javascripts",
# "/Users/Augusto/Sites/wisegrowth/app/assets/pdf",
# "/Users/Augusto/Sites/wisegrowth/app/assets/stylesheets",
# "/Users/Augusto/Sites/wisegrowth/vendor/assets/javascripts",
# "/Users/Augusto/Sites/wisegrowth/vendor/assets/stylesheets",
# "/Users/Augusto/.rvm/gems/ruby-1.9.3-p551/gems/jquery-rails-2.3.0/vendor/assets/javascripts",
# "/Users/Augusto/.rvm/gems/ruby-1.9.3-p551/gems/coffee-rails-3.2.2/lib/assets/javascripts",
# "/Users/Augusto/.rvm/gems/ruby-1.9.3-p551/gems/formtastic-2.1.1/app/assets/stylesheets"
# ]
Run Code Online (Sandbox Code Playgroud)
但是当我跑步的时候
rake assets:precompile RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)
一切都是预编译但是pdf文件和我在Heroku上的生产应用程序中我收到以下错误:
ActionView::Template::Error (ricerca_wg.pdf isn't precompiled):
Run Code Online (Sandbox Code Playgroud) asset-pipeline ×10
coffeescript ×2
heroku ×2
sprockets ×2
apache ×1
css ×1
execjs ×1
javascript ×1
mod-deflate ×1
ruby ×1
turbolinks ×1