在我中,production.rb我设置为:
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://myassets.com"
Run Code Online (Sandbox Code Playgroud)
图像,js和样式表可以从我的CDN(资产服务器)正常加载
但是如果有一天该资产服务器出现故障怎么办?并返回404?
因为在资产服务器(CDN)中我已经配置了a pull zone,所以该内容仍然可以从获得/assets/..。
是否有任何后备,或者如何进行后备,所以当我assets server失败或返回错误时,我的应用程序会从/assets/应用程序内部加载资产?
我有一个应用程序,允许用户为他们的页面选择一个主题.有几种不同的主题供他们选择.
每个页面的HTML结构与div上的相同类名完全相同.CSS会有所不同以填写主题.当用户选择主题时,我将主题id存储在数据库中,并在访问页面时对其进行查询,并在以下位置加载相应的CSS文件application_layout.html.erb:
<%= yield(:theme_style) %>
Run Code Online (Sandbox Code Playgroud)
在users_page.html.erb,我抓住适当的文件:
<%= provide(:theme_style, "theme_styles/#{@user.style.style_filename_file_name}") %>
Run Code Online (Sandbox Code Playgroud)
由于页面结构不会发生变化,因此重要的是CSS文件不能在一个大的CSS文件中一起编译,否则最后一个主题将是唯一可用的,因为它将覆盖所有以前的样式.如何让Rails处理主题文件?
在production.rb,我有,config.assets.precompile += ['theme_styles/basic.css', 'theme_styles/two-column.css']但似乎没有做伎俩,因为它告诉我它没有预编译.
我似乎无法在任何地方找到足够的信息来让我朝着正确的方向前进,我已经查看了博客,SO问题和Rails文档.
编辑: 结果我的初始问题不再准确 - 问题与dataTables gem没有直接关系,我相信这与我的Apache2配置有关.
我似乎有一个问题,jquery-datatables-rails gem与rails资产管道很好地配合.
这个问题最初看起来与这个问题类似,但是从那里出现解决方案的明显路径并没有愉快地解决问题.
gem在我的Gemfile中,根据railscast第340集中的指示为我的一个html表安装和实现.在开发模式下运行应用程序,bundle exec rails s工作正常,并且所有dataTables功能都出现在网站上没有问题.
当我尝试在生产环境中运行网站时 - 使用capistrano或只是bundle exec rails s -e production- 在预编译资产之后,不使用编译的文件,尽管它们都会编译为公共/资产.
当使用config.assets.compile = true代替预编译时,它似乎也没有显示dataTables功能.(我相信这两者是对立的,但我可能会误解)
当我进入页面并查看js错误控制台时,没有错误,它只是呈现计划html表.
我无法弄清楚是什么导致网页无法呈现dataTables,我尝试的每一次搜索都在上面链接的问题上加上一遍又一遍的其他五个页面.这些解决方案似乎都不是我的铁杆野兽所渴望的.
你们中的任何人都对问题可能有什么了解吗?
部分相关文件:
应用程序/资产/ Java脚本/ charts.js.coffee:
jQuery ->
$('#charts').dataTable({
"oSearch": {"bSmart": "true", "sSearch": "vdo"}
"iDisplayLength": 50
})
Run Code Online (Sandbox Code Playgroud)
应用程序/资产/ JavaScript的/ application.js中
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require_self
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
应用程序/资产/样式表/ application.css
*= require_self
*= require dataTables/jquery.dataTables
*= require_tree …Run Code Online (Sandbox Code Playgroud) 我在production.rb中有以下配置
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Choose the compressors to use
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :yui
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs.
config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)
但是当生产服务器上的ruby on rails应用程序出现以下错误:
Error compiling CSS asset
LoadError: cannot load such file -- yui-compressor
Run Code Online (Sandbox Code Playgroud)
在评论线上LoadError: cannot load such …
例如,在我的Rails应用程序中,我有类似的东西:
.wax_seal {
background: url("wax-seal-small.png");
display: block;
height: 100px;
margin: 0 auto;
width: 92px;
}
.wax_seal:active {
background: url('wax-seal-small-broken.png');
}
Run Code Online (Sandbox Code Playgroud)
在我的config/environments/production.rb文件中:
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)
我手动调用资产的编译:
bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
并且在名称末尾使用哈希创建文件:
wax-seal-small-Uuhqwduhqwdoi234983jewf.png
Run Code Online (Sandbox Code Playgroud)
所以这不起作用:
background: url("wax-seal-small.png");
Run Code Online (Sandbox Code Playgroud)
但这很好(当我在Chrome中手动输入时):
background: url("wax-seal-small-Uuhqwduhqwdoi234983jewf.png");
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么一步?如何让我的CSS规则添加到那个小哈希?
添加config.assets.compile = true在config/environments/production.rb使得它的工作,但我由于显著性能命中阅读Rails的指导,这是一个不好的做法.
我在许多RubyOnRails应用程序中多次需要CSS样式表,实际上我需要一些揭秘的东西.
有什么区别:
//=require mystyles
Run Code Online (Sandbox Code Playgroud)
和
*=require mystyles
Run Code Online (Sandbox Code Playgroud)
两者似乎都有效,那有什么区别?
这是资产管道的一部分还是SASS的一部分还是普通的CSS?
我在跑
RAILS_ENV=staging bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
在两台不同的机器上,为同一资产文件获取不同的指纹.我在两台机器上安装了Rails 4.0.2.机器是
无论资产编制在哪台机器上,指纹都不应该是相同的吗?
编辑:Linux机器是EC2实例.所以我制作了它的AMI并启动了第二个实例.在此相同实例上编译资产会产生与在原始实例上创建的指纹相同的指纹.这似乎是我的开发机器的"问题".
md5 ruby-on-rails fingerprint asset-pipeline ruby-on-rails-4
在我的Rails 4应用程序中,我有一个users.js.coffee文件app/assets/javascripts.它编译并在开发中正常工作.但是,当我部署到heroku时,它无法正常工作.据Railsguides说:
匹配器(以及预编译数组的其他成员;请参见下文)应用于最终编译的文件名.这意味着排除了编译为JS/CSS的任何内容,以及原始JS/CSS文件; 例如,.coffee和.scss文件在编译到JS/CSS时不会自动包含.
所以我在我的网站上添加了以下内容 config/environments/production.rb
config.assets.precompile += %w ( users.js.coffee )
Run Code Online (Sandbox Code Playgroud)
它仍然没有强制文件被预编译.你知道我怎么可能强迫Rails预编译它(我RAILS_ENV=production bundle exec rake assets:precompile用来预编译)?
非常感谢.
ruby-on-rails precompile coffeescript asset-pipeline ruby-on-rails-4
在生产中,不使用图像标记调用图像的正确路径,并且不添加md5指纹.图像名称(例如"pretty_picture.jpg")存储在数据库中.预编译文件都存在于公共文件夹中,包括清单文件.
使用image_tag调用时:
image_tag @test_question.question.image
Run Code Online (Sandbox Code Playgroud)
我明白了:
<img src="/images/pretty_picture.jpg">
Run Code Online (Sandbox Code Playgroud)
如果我在production.rb中设置config.assets.compile = true,则渲染图像,我得到:
<img src="/assets/images/pics/pretty/pretty_picture-e0df5012b6930cda4efaa866af22a63f.jpg" >
Run Code Online (Sandbox Code Playgroud)
我的黑客解决方案是使用(在HAML中)
%img{src: "/assets/"+Rails.application.assets.find_asset(@test_question.question.image).digest_path}
Run Code Online (Sandbox Code Playgroud)
在production.rb我有
config.assets.digest = true
config.assets.enabled = true
config.serve_static_files = false
config.assets.compile = false
Run Code Online (Sandbox Code Playgroud)
建议不要在生产中将config.assets.compile设置为true.这似乎是代表链轮和资产管道的非常奇怪的行为.知道在这里使用image_tag有什么问题吗?
什么是资产管道插件和资源插件?
它们之间有什么区别?
有哪些优点和缺点?
这是强制使用不同的js和css框架吗?
asset-pipeline ×10
sprockets ×2
apache2 ×1
assets ×1
cdn ×1
coffeescript ×1
css ×1
fallback ×1
fingerprint ×1
grails ×1
md5 ×1
precompile ×1
sass ×1