Rails 3.1 和 sprockets 使使用 firebug 进行调试变得更加困难?

发布于 2024-11-10 02:28:40 字数 532 浏览 4 评论 0原文

在 Rails 3.1 中,Sprocket 用于管理资源并将它们打包到单个文件中。一般来说,这并不是一个坏主意。

正如外部来源引用的那样,它解释了当前的问题:

这种方法的一个问题是 它可能会使调试变得更加困难,如果你 必须看看“串联”CSS 生产中的文件有意义 包含什么代码,不包含什么代码,它是 更难知道什么来自哪里 比你只包含原来的 源代码文件。

一个解决方案是有办法 在“串联”和“串联”之间切换 轻松“正常”模式(也许是 已经可能了,我不知道),所以 正常的发展应该是 畅通。但你必须求助于 大的串联文件 生产中的调试。

在 Rails 3.0.X 中,我们的设计人员可以使用 Firebug 轻松定位 CSS 设置,Firebug 会直接指示文件和行号,因为所有 CSS 文件都是独立的,没有打包成一个。

或者我错过了重点?

In Rails 3.1, Sprockets are used to manage assets and package them into a single file. Which, in general, is not such a bad idea.

As quoted from an external source, which explains the issue at hand:

A problem with this approach is that
it could make debugging harder, if you
have to look at the "concatenated" CSS
file in production to make sense of
what code's included and not, it's
harder to know what comes from where
than if you just included the original
source code files.

One solution would be to have a way to
switch between "concatenated" and
"normal" modes easily (maybe it's
already possible, I don't know), so
that normal development would be
unimpeded. But you'd have to resort to
the big concatenated file for
debugging in production.

In Rails 3.0.X, our designer could easily pin-point the CSS setting using Firebug, which will indicate the file and line number directly, since all CSS files were separate and not packaged into one.

Or am I missing the point?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

你与昨日 2024-11-17 02:28:40

您还可以使用:

<%= stylesheet_link_tag "application", :debug => Rails.env.development? %>
<%= javascript_include_tag "application", :debug => Rails.env.development? %>

这些文件在开发中不会串联,但在其他环境中会串联。

You can also use :

<%= stylesheet_link_tag "application", :debug => Rails.env.development? %>
<%= javascript_include_tag "application", :debug => Rails.env.development? %>

The files will not be concatenated in development but will in other environments.

摘星┃星的人 2024-11-17 02:28:40

将 ?debug_assets=true 添加到要调试的任何 URL。它将资产分成各个部分。如果没有它,串联将根据您的环境设置进行。

Add ?debug_assets=true to any URL you want to debug. It splits the assets into their parts. Without it, concatenation happens according to your environment settings.

╰つ倒转 2024-11-17 02:28:40

我认为最终(当 RC 接近/成为版本时)您将能够使用以下内容修改您的 config/application.rb
config.assets.css_compressor = false

但是,atm,这并不能真正解决这个问题,因为 stylesheet_asset_tag 辅助函数与新管道不完全兼容,并且 :all 修饰符不起作用,所以......

在你的 application.html.erb 视图,您将必须链接每个 css

<%= stylesheet_link_tag "stylesheets/application" %>
<%= stylesheet_link_tag "stylesheets/foo" %>
<%= stylesheet_link_tag "stylesheets/bar" %>

只要您的 config/application.rbconfig.assets.enabled = true > 资产的根目录将是(默认情况下)/assets

您可以启动 Rails 控制台 (rails c) 和 p Rails.application.assets 查看同时可配置的属性。

我同意这不是最好的解决方案,但在这一点上(使用 RC 与稳定版本)这是我发现的最好的方法。

更新:挖掘边缘API,发现这个ActionView::Helper sprockets_stylesheet_link_tag (http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/SprocketsHelper.html)但它似乎仍然是 stylesheet_link_tag 的不完整替代品,因为它不支持 :all 并且您仍然必须在函数调用中包含 stylesheets/ 段。话虽如此,它可能是继续使用的功能,所以......

<%= sprockets_stylesheet_link_tag "stylesheets/foo" %>

I think in the end (when the RC gets closer/becomes a release) you will be able to modify your config/application.rb with the following
config.assets.css_compressor = false

But, atm, that doesn't really fix it since the stylesheet_asset_tag helper function isn't exactly compatible with the new pipeline and the :all modifier doesn't work, so...

In your application.html.erb view you will have to link each css

<%= stylesheet_link_tag "stylesheets/application" %>
<%= stylesheet_link_tag "stylesheets/foo" %>
<%= stylesheet_link_tag "stylesheets/bar" %>

As long as you have config.assets.enabled = true in your config/application.rb the root of assets will be (by default) /assets

You can fire up a rails console (rails c) and p Rails.application.assets to see the properties that are configurable in the mean time.

I agree not the best solution, but at this point (using an RC vs a stable release) its the best way I've found.

UPDATE: Digging around the edge api, found this ActionView::Helper sprockets_stylesheet_link_tag (http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/SprocketsHelper.html) but it seems to be still an incomplete replacement for stylesheet_link_tag since it doesn't support :all and you still have to have the stylesheets/ segment in your function call. With that said, its prolly the function to use moving forward, so...

<%= sprockets_stylesheet_link_tag "stylesheets/foo" %>
放血 2024-11-17 02:28:40

您还可以使用:

<%= stylesheet_link_tag "application", :debug =>true%>
<%= javascript_include_tag "application", :debug => true %>

它将在浏览器的查看源代码中为您提供以下输出

 <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
 <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
 <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
 <script src="/assets/application.js?body=1" type="text/javascript"></script>

You can also use :

<%= stylesheet_link_tag "application", :debug =>true%>
<%= javascript_include_tag "application", :debug => true %>

It Will gives you following output in view source of your browser

 <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
 <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
 <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
 <script src="/assets/application.js?body=1" type="text/javascript"></script>
○闲身 2024-11-17 02:28:40

我发现了一个有趣的问题。如果我预编译资产(提交到 git 中),在生产模式下进行测试,然后返回到在同一台计算机上使用开发环境,我就会看到这个问题。

即使我回到开发模式,公共/资产的内容也会被缓存和提供,而不是新的资产内容。所以这是我修复它的方法:

rm -rf public/assets

I found an interesting issue. If I precompile assets (to commit into git), test in production mode, and then go back to using a development environment on the same machine, I see this problem.

Even though I'm back in development mode, the contents of public/assets are being cached and served instead of fresh asset contents. So here's how I fixed it:

rm -rf public/assets
手心的海 2024-11-17 02:28:40

sprockets 可能只能在生产环境中工作,在开发和测试期间无需将所有内容打包到单个文件中

sprockets probably will work only in production environment, there's no need to package everything into a single file during development and test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文