该滑轨资产管道指南将指导您使用config.assets.paths的config/application.rb,但我没有在这一点上访问请求的子域.
我希望能够根据请求的子域前置一个额外的路径(仅针对当前请求).
我的申请具体细节
这是一个基本的CMS应用程序.根domain.com主机使用标准控制器/视图呈现和默认资产路径处理管理部分.
请求以此subdomain.domain.com为基础呈现网站subdomain.它只调用prepend_view_patha before_filter并Rails.root.join('vendor/sites/[subdomain]/templates')为当前请求添加 .
我希望能够Rails.root.join('vendor/sites/[subdomain]/assets')在请求主机时添加到Sprockets搜索路径[subdomain].domain.com.
编辑
我最后只是在mixin中删除了Sprockets::Environment覆盖调用方法:
module SiteAssetsResolver
def call(env)
begin
# prepend path based on subdomain (from env)
super # Sprockets::Server#call
ensure
# remove path based on subdomain
end
end
end
MyApp::Application.assets.extend(SiteAssetsResolver)
Run Code Online (Sandbox Code Playgroud) assets ruby-on-rails ruby-on-rails-3.1 sprockets asset-pipeline
我正在Heroku Cedar堆栈上运行rails 3.1 app,它支持资产管道.Heroku 列出了3种编译资产的方法
显然#3对性能有害,而Heroku文档也建议不要这样做.但我不确定#1和#2之间哪个更好.
#1要求您运行rake assets:precompile并public/assets在git中包含您的文件夹.你的slug会更大,但我认为部署网站的停机时间会更短.但更大的段塞大小意味着应用程序启动速度较慢,所以也许这是一个洗牌.
由于在Heroku端进行预编译,#2将使部署更新需要更长的时间.但是,你会有一个较小的slu and,而且管理/记忆的次数较少.
我的问题是 - 哪种选择(#1或#2)最适合生产,为什么?
到目前为止它看起来像选项#2但我想确保我不会忽视某些东西.
运行时:
rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
Run Code Online (Sandbox Code Playgroud)
一切都是预编译但不是我的 /app/assets/images/*
我甚至尝试将此添加到我的 environment/production.rb
config.assets.paths << "#{Rails.root}/app/assets/images"
Run Code Online (Sandbox Code Playgroud)
怎么了?谢谢!
如何将Rails 3.1管道的预编译资产部署到s3?
我需要一个任务来自动执行与资产存储桶同步的工作.
编辑:
这个gem正是我需要的:https://github.com/rumblelabs/asset_sync.
Rails 3.1.0.rc5
我在命令路由在启用ERB的Javascript文件中工作时遇到问题:
# app/assets/javascripts/items.js.erb
$('#start').click(function() {
$.ajax({
url : '<%= ajax_items_path %>',
success : function(result) {
$('#result').html(result);
}
});
});
Run Code Online (Sandbox Code Playgroud)
错误消息如下:
Error compiling asset items.js:
NameError: undefined local variable or method `ajax_items_path' for #<#<Class:0x007fbcb49a7630>:0x007fbcb4ee30b8>
(in myproject/app/assets/javascripts/items.js.erb)
Run Code Online (Sandbox Code Playgroud)
ajax_items_path如果我直接在视图中使用它,该路径工作正常.
看起来资产管道中没有命名路由.如果是这种情况,那么解决方法是什么?我真的想避免在我的Javascript中硬编码URL.
是否有可能在Rails3中破解记录器以忽略对资产的请求?
当它充满时,在日志中找到一些东西是疯狂的
Started GET "/assets/tiscali.png" for 127.0.0.1 at 2011-09-09 19:59:45 +0200
Served asset /tiscali.png - 304 Not Modified (0ms)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我使用codekit编写less,然后自动转换为css.
我不希望rails将我较少的文件转换为css,我更喜欢codekit.
如果我通过预编译资产
rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
我明白了
rake aborted!
cannot load such file -- less
Run Code Online (Sandbox Code Playgroud)
如何从预编译中排除特定文件夹/文件类型?(我所有较少的文件都在app/assets/stylesheets/less中,css(我想要预编译)在app/assets/stylesheets/css中
更新
删除application.less解决了这个问题,但我如何将其从处理中排除?
less precompile ruby-on-rails-3 asset-pipeline ruby-on-rails-3.2
我正在尝试将我的应用程序部署到Heroku.Heroku没有加载我的js和css文件
我跑了RAILS_ENV=production bundle exec rake assets:precompile
,它仍然无法正常工作.
然后我跑了
heroku rake assets:precompile
我在Heroku日志中收到此错误:
Error compiling asset application.css:
Sprockets::FileNotFound: couldn't find file 'jquery.ui.datepicker'
(in /app/app/assets/stylesheets/application.css.scss:13)
Served asset /application-989f5e5266d9b066eb316183d7db5c77.css - 500 Internal Server Error
Error compiling asset application.js:
Sprockets::FileNotFound: couldn't find file 'jquery.ui.datepicker'
(in /app/app/assets/javascripts/application.js:16)
Served asset /application-d81c946c6f47242e5e97de9bca4938be.js - 500 Internal Server Error
Run Code Online (Sandbox Code Playgroud)
config production.rb:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.initialize_on_precompile = false …Run Code Online (Sandbox Code Playgroud) 如何在Rails开发模式下以缩小(编译)形式呈现我的资产?
我有几十个资产文件,因为它们一个接一个地提供服务,所以在开发中加载页面之前需要很长时间.我相信如果我保持编译并从中获得服务会加快我的页面加载时间(我知道当我专门处理资产时这并不理想).
这是布局中的样式和脚本标记
<%= stylesheet_link_tag 'all' %>
<%= javascript_include_tag 'all' %>
Run Code Online (Sandbox Code Playgroud)
而且我也跑了 bundle exec rake assets:precompile:nondigest
但我仍然看到资产一个接一个地呈现.请帮忙!
如果我有压缩的rails资产,我是否必须配置nginx来压缩资产(gzip设置为on)rake assets:precompile?我的意思是它有意义吗?性能会更好还是更差?谢谢!
asset-pipeline ×10
heroku ×2
sprockets ×2
amazon-s3 ×1
assets ×1
less ×1
nginx ×1
precompile ×1
ruby ×1