如何防止div的宽度扩展超过百分比和像素?换句话说,浏览器应计算百分比的像素值,然后选择两个值中的较低者.
如果我将它们设置为这样:{max-width:100px;max-width:20%;}资产管道只选择第二个并忽略第一个.
我一直在关注Michael Hartl出色的RoR教程,但我正在使用RoR 3.1.我是RoR 3.1的新手,需要有关资产管道的帮助.这是我的问题:
在继续讨论第5.3节之前,我想我想推进Heroku,看看事情是如何发展的.令我惊讶的是"GET /"导致错误500.在我的本地开发环境中一切都很好.然后我尝试在production-environment(rails s -e production)下运行我的本地sample_app .相同的结果,错误500:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Pages#home
Showing /Users/john/Projects/sample_app/app/views/layouts/_stylesheets.html.erb where line #4 raised:
blueprint/screen.css isn't precompiled
Run Code Online (Sandbox Code Playgroud)
支持信息:
我按照Michael的第13.1.4节建议进行操作,并将以下内容作为我的app/views/layouts/application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= render 'layouts/stylesheets' %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container">
<%= render 'layouts/header' %>
<section class="round">
<%= yield %>
</section>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)app/views/layouts/_stylesheets.html.erb的内容:
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<%= …Run Code Online (Sandbox Code Playgroud)为了在我的heroku生产环境中调试javascript,我需要禁用资产压缩(或者至少压缩javascript).我试着config.assets.compress = false沿config.assets.debug = true,并仍在使用的压缩资产.然后我删除了压缩资产,此时根本没有资产.我补充说config.assets.enabled = false,这没有帮助.我尝试将未压缩的资源复制到各种目录中,包括应用程序root,public和public/assets(后两个使用文件夹"images",javascripts"和"stylesheets"),并将资源直接放入文件夹中三个子文件夹).我最终能够通过更改html来直接引用所有的javascript文件来使javascripts工作.但CSS和图像仍然无法正常工作.
我原以为我原来config.assets.compress = false应该有用.我做错了什么想法?
我有点困惑,因为似乎application.css包含了两次,一次是它从清单中列出资源然后是缓存.因此,当我删除单个文件时,它似乎仍然在application.css文件中保持活着状态.
/*
*= require twitter/bootstrap
*= require_self
*= require_tree ./common
*= require_tree ./helpers
*/
Run Code Online (Sandbox Code Playgroud)
它按预期工作,并以开发模式输出所有相关的单个文件
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
Run Code Online (Sandbox Code Playgroud)
<link href="/assets/twitter/bootstrap.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/common/announcement.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/common/button.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<Blah blah>
Run Code Online (Sandbox Code Playgroud)
这应该是空白的吗?因为我在application.css文件中的所有内容都是清单而没有实际的css,但我得到的所有连接代码都是106kb.
IE如果我删除公共目录中的文件,它不会消失.它不再列在输出中,但css仍然出现在application.css中
我遇到了Rails 3.1资产管道的问题.资产包括两次开发:
<script src="/assets/main_new.js?body=1" type="text/javascript"></script>
<script src="/assets/pagenav.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.controller.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
Rails以某种方式编译并包含application.js,因此所有脚本都包含两次 - 作为单个文件和application.js
生产中的预编译资产一切都很好.
development.rb
config.assets.compress = false
config.assets.debug = true
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 both stylesheets and JavaScripts
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss
config.assets.compile = false
config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)
application.rb中
config.assets.enabled = true
Run Code Online (Sandbox Code Playgroud) Microsoft的IE支持文档在Internet Explorer 6-9中解释了这一点:
- 不应用前31个样式标记之后的所有样式标记.
- 不应用前4,095条规则之后的所有样式规则.
- 在使用@import规则连续导入导入其他样式表的外部样式表的页面上,将忽略深度超过三级的样式表.
我们需要一种方法来分割由资源管道中的Sprockets生成的已编译样式表,以使最大选择器数保持在4096以下,并在部署的Rails应用程序的HTML中链接到它们.我们如何将已处理资产(特别是样式表)的编译输出作为参数传递给可以修改文件的方法?
请参阅以下尝试开始的地方.如果有人可以帮我找到一种方法来制作可操作的(或者一种全新的解决方案),那就太棒了!
创建Bless是为了解决这个问题,方法是拆分样式表以使每张纸的最大选择器数量保持在限制之下.Bless在node.js的服务器上运行.我还没有看到类似Ruby的东西.Eric Fields试图将用罗盘编译的资产提供给Bless(在节点中运行),但该解决方案依赖于Compass处理资产编译,因此似乎不适用于资产管道.请注意,Bless不是链接到多个样式表,而是将@include语句添加到第一个工作表,这可能是要避免触及标记的方法.
当Christian Peters(@crispy)发现这个问题时,他实现了像Bless这样的分离器,它也将Compass输出传递给自定义模块,该模块在Rails 3.1之前运行良好.后来,他使用SprocketsEngine调整了他的拆分器,以便与Rails Asset管道集成.我已经尝试实现新代码,但它似乎没有自动运行(虽然在控制台中手动调用时分割器工作正常).
有关IE 6-9中CSS限制的更多信息,请参阅以下相关问题:
css internet-explorer ruby-on-rails sprockets asset-pipeline
我正在向Heroku的Cedar堆栈部署一个Rails 3.1应用程序.使用Heroku Cedar和Rails 3.1,您可以在本地自己编译资源,让Heroku在推送时(在"slug编译"期间)编译它们,或者在应用程序运行时及时编译它们.我想做中间选项,让Heroku预编译资产.
当Heroku运行资产:预编译任务时,它会因"无法连接到服务器"而出错,因为应用程序正在尝试连接到数据库但在slug编译阶段没有可用的数据库.此时缺乏数据库连接是预期的,也是不可避免的.我正在寻找一种方法来超越它,因为数据库连接对资产预编译并不重要.
我的应用程序试图连接到数据库的部分是Devise.devise_for :users在routes.rb中有一行想要查看用户模型.
我可以编写一个rake任务来存储devise_for并使其成为资产的先决条件:预编译.我认为这可以解决我的问题,但我正在寻找一个更通用的解决方案,我可以在任何 Rails 3.1应用程序上使用Heroku上的这个问题.
那里有什么东西,或者你能想到任何能够在运行应用程序足以产生路由和资产路径的同时消除数据库连接错误的东西吗?
显然,如果一个应用程序需要在启动期间读/写数据,我们不能存根,但我们可以自动伪造每个ActiveRecord模型吗?
我正在使用Paperclip并为我的一个附件设置了一个default_url选项:
:default_url => '/images/missing_:style.png'
Run Code Online (Sandbox Code Playgroud)
自从目录移动后,资产管道显然不喜欢这样.处理这个问题的最佳方法是什么?我对这张照片有两种风格(迷你和拇指).
我试图使用命令预编译资产rake assets:precompile RAILS_ENV=production,但我总是得到以下错误.
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/bin/ruby /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
LoadError: cannot load such file -- uglifier
(in /home/cool_tech/cool_tech/app/assets/javascripts/application.js)
/usr/lib/ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/usr/lib/ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
/usr/lib/ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/lib/ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/usr/lib/ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/compressors.rb:31:in `registered_js_compressor'
/usr/lib/ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/bootstrap.rb:18:in `block in run' …Run Code Online (Sandbox Code Playgroud) ruby-on-rails precompile ruby-on-rails-3 asset-pipeline ruby-on-rails-3.2
CSS不会加载到我的rails应用程序中.这是位于view/products中的index.html.erb文件:
<h1>Listing products</h1>
<table>
<% @products.each do |product| %>
<tr class="<%= cycle('list_line_odd', 'list_line_even') %>">
<td>
<%= image_tag(product.image_url, :class=> 'list_image') %>
</td>
<td class="list_description">
<dl>
<dt><%= product.title %></dt>
<dd><%= truncate(strip_tags(product.description), :length=> 80) %></dd>
</dl>
</td>
<td class="list_actions">
<%= link_to 'Show', product %><br/>
<%= link_to 'Edit', edit_product_path(product) %><br/>
<%= link_to 'Destroy', product,
:confirm=> 'Are you sure?',
:method=> :delete %>
</td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New product', new_product_path %>
Run Code Online (Sandbox Code Playgroud)
然后我将application.html.erb文件放在view/layouts中.此文件应将css链接到html.
<!DOCTYPE html>
<html>
<head>
<title>Depot</title>
<%= stylesheet_link_tag "application" …Run Code Online (Sandbox Code Playgroud) asset-pipeline ×10
css ×3
assets ×1
compression ×1
css3 ×1
database ×1
heroku ×1
html ×1
javascript ×1
paperclip ×1
precompile ×1
sass ×1
sprockets ×1