我正在使用 Rails 3.2 和 jquery-ui-rails 插件将日期选择器添加到我的 JS 清单文件中。
这是我的清单文件:
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
我将我的 jQuery 库与 Google 的 CDN 分开。
但是,通过将 jquery.ui 添加到清单文件中,它会自动包含其 jQuery 依赖项 - 所以现在我在最终的 HTML 文档中得到了两个 jQueries。
我不想要这个额外的 jQuery 文件——我只想要来自 Google 的 CDN 的那个。使用链轮,我可以使用 stub 指令有选择地“排除”jQuery 文件。
所以这就是我所做的 - 它不起作用 - 即 jQuery 仍然添加到我的最终 JS 文件中......
//= stub jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
我尝试了几种组合:
//= stub jquery.js
//= stub "jquery"
//= stub "jquery.js"
//= stub "/jquery.js"
Run Code Online (Sandbox Code Playgroud)
等等 …
我不知道现在有什么不同,但从几天前开始,跑步rake assets:precompile就永远挂了。这仅在我设置时发生RAILS_ENV=production。
如果我tail -f production.log,我可以看到这个:
Compiled rails_admin/jquery.pjax.js (0ms) (pid 28704)
Compiled jquery_nested_form.js (0ms) (pid 28704)
Compiled rails_admin/ra.nested-form-hooks.js (233ms) (pid 28704)
Compiled bootstrap.js (10ms) (pid 28704)
Compiled rails_admin/ra.widgets.js (240ms) (pid 28704)
Compiled rails_admin/ui.js (100ms) (pid 28704)
Compiled rails_admin/themes/default/ui.js (0ms) (pid 28704)
Compiled rails_admin/custom/ui.js (0ms) (pid 28704)
Compiled rails_admin/rails_admin.js (1121ms) (pid 28704)
Compiled rails_admin/jquery.colorpicker.css (50ms) (pid 28704)
Compiled rails_admin/imports.css (9460ms) (pid 28704)
Compiled rails_admin/rails_admin.css (9472ms) (pid 28704)
Run Code Online (Sandbox Code Playgroud)
由于rails_admin/rails_admin.css是最后出现的东西,似乎rails_admin.css可能是罪魁祸首。唯一要做的rails_admin.css就是包含一个名为 的文件imports.css.scss.erb …
我正在将我的 rails 3.2.14 应用程序部署到 2 个不同的服务器,它们前面有一个负载平衡器。资产目前正在服务器上预编译(通过 capistrano 部署)。
出于某种原因,application.js 文件上的指纹在两个服务器之间是不同的。源文件是相同的。如果我//= require_tree .从 application.js 中删除 ,那么它们都神奇地具有相同的指纹。
我遇到过一些提到这个问题的帖子,但从未真正解决根本原因:
我试图避免在本地预编译资产作为解决这个问题的一种方式(至少现在......)。
我目前正在使用带有 jQuery UI 的 Rails 4.0.2(主要用于日期选择器)。我的生产环境是 Heroku。
我的主要问题是我的主题的图像没有在生产中提供(虽然它在开发中运行良好)。我将这样的主题 css 包含在我的application.css:
*= require_self
*= require_tree .
*= require jquery-ui-1.10.4.custom
Run Code Online (Sandbox Code Playgroud)
主题的 css 显示正常,但没有任何图像正常工作。我已经阅读了关于 StackOverflow 的无尽问题、博客和 Github 上的讨论——没有一个对我有用。我还通读了 Edge Rails 指南,该指南没有提及图像预编译,尽管从 Github 上的讨论来看,这似乎在 Rails 4 中确实发生了变化。
这是我当前的目录结构:
/vendor
/assets
/stylesheets
jquery-ui-1.10.4.custom.css
/images
animated-overlay.gif
ui-bg_flat_0_aaaaaa_40x100.png
(more images like these)
Run Code Online (Sandbox Code Playgroud)
据我所知,集成外部 css 和 javascript 库的正确方法是将这些资产放在 /vendor/assets 中,这就是我正在做的。
同样,我的问题是 rails 断然拒绝为生产中的任何资产提供服务。我可以摆弄图像 URL,但它根本没有得到服务。
以下是我尝试过的事情:
如果我运行,rake assets:precompile我只会在 public/assets 中看到 2 个文件 - 一个 css 文件和一个 javascript 文件。我假设这是错误的,Rails 实际上也应该将我的图像放在那里。
根据这个问题——rails …
我做了 RAILS_ENV=production rake assets:clean; RAILS_ENV=production rake assets:precompile --trace
我得到了
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(in /Users/hsu-wei-cheng/Dropbox/Rails/dqa_dev_server/vendor/themes/lenord-single-page-theme/application.css)
(sass):7322
Run Code Online (Sandbox Code Playgroud)
然而在 lenord-single-page-theme/application.css
/*
*= require_self
*= require_tree .
*/
Run Code Online (Sandbox Code Playgroud)
我注释掉了所有 config.assets.precompile
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
#config.assets.precompile += %w( bootstrap.css )
# config.assets.precompile += %w( vendor/themes/* )
#config.assets.precompile += %w( vendor/themes/**/application.js )
#config.assets.precompile += %w( vendor/themes/**/application.css )
# config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的rails应用程序部署到生产中,并且我正在尝试预编译所有资产:
我的assets.rb文件:
Rails.application.config.assets.precompile += %w( *.css.sass )
Rails.application.config.assets.precompile += %w( *.css.scss )
Rails.application.config.assets.precompile += %w( *.css )
Rails.application.config.assets.precompile += %w( *.js )
Rails.application.config.assets.precompile += %w( *.js.coffee )
Rails.application.config.assets.precompile += %w( *.js.coffee.erb )
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用capistrano进行部署时,出现以下错误:
DEBUG[c79c6191] rake aborted!
DEBUG[c79c6191] Sass::SyntaxError: Undefined variable: "$alert-padding".
Run Code Online (Sandbox Code Playgroud)
在我之前的assets.rb文件中,我已经逐个文件地添加了每个资产,并且部署正在运行,但是,我正在布局文件中导入一些资产:
<%= javascript_include_tag 'application', 'jquery-ui-1.9.2', 'js-example', 'js-example2', 'data-turbolinks-track' => true %>
Run Code Online (Sandbox Code Playgroud)
但我也使用链轮导入一些:
//= require jquery
//= require bootstrap-sprockets
//= require angular
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
这个方法在我开发应用程序时运行良好,但是当我将应用程序部署到生产环境时,似乎我使用链轮导入的东西没有被导入(即Angular)
提前致谢.
编辑:根据要求,我的application.css.scss文件:
/*
*
*= require_tree .
*= …Run Code Online (Sandbox Code Playgroud) 这是跟踪输出: 这是什么:can't dump anonymous class东西?不知道我还能尝试什么。我真的很欢迎你的帮助。谢谢!!
heroku run rake assets:precompile --trace
Running `rake assets:precompile --trace` attached to terminal... up, run.1662
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
I, [2014-10-17T01:54:29.696549 #2] INFO -- : Writing /app/public/assets/10code-7079b1d91d9d7c7a9a2338cea73f8a82.jpg
I, [2014-10-17T01:54:29.698443 #2] INFO -- : Writing /app/public/assets/favicon-a74691afc8a111f00d70667670a61182.ico
I, [2014-10-17T01:54:37.258312 #2] INFO -- : Writing /app/public/assets/application-16c68220ab8dd6d871a35138ee0901f0.js
Warning. Error encountered while saving cache 377616f718d2970e646cd030c1890fad19bd5c36/about.css.scssc: can't dump anonymous class #<Class:0x007f7cefb6b200>
Warning. Error …Run Code Online (Sandbox Code Playgroud) 随着我继续在我的应用程序上取得进展,我的样式表文件夹很快就会溢出。我已经阅读了关于资产管道的 rails 指南,并在互联网上搜索了一个有信誉的来源,但仍然在“rails 方式”上不知所措,以保持一切整洁。
在我去尝试自己开发一个系统之前,我希望能从你们那里得到一些建议。
在资产组织方面是否有众所周知的“最佳实践”?如果没有,什么对你来说效果很好?
截至目前,我的设置是这样的:
app/assets/stylesheets >
Run Code Online (Sandbox Code Playgroud)
application.css, 应用程序-RESPONSIVE.css
任何特定于正文、容器、导航栏、页脚的代码
controller.scss,控制器响应
*任何特定于该控制器的代码
lib/assets/stylesheets >
Run Code Online (Sandbox Code Playgroud)
重置.css
在 application.css 我使用
*= require reset
*= require_tree .
*= require_self
Run Code Online (Sandbox Code Playgroud)
然而,为了获得所有样式,我也一直在想,如果需要,在树之前设置self作为覆盖主要样式的方法是否更好?
css ruby-on-rails organization ruby-on-rails-3 asset-pipeline
我正在使用在线生成器(http://realfavicongenerator.net但其他生成器,例如 www.favicon-generator.org 工作相同)来实现收藏夹图标。生成器提供了近 30 个文件(用于 android、苹果、不同大小等的图像),这就是为什么我将所有这些文件放在资产管道 ( assets/images/favicons/) 而不是公共文件夹中(否则会变得如此混乱)。
文件中包含一个 xml 文件browserconfig.xml和一个 json 文件manifest.json(不确定它们的确切用途)。在标题中,我使用以下方法加载两个文件:
<%= content_tag :meta, nil, content: image_path("favicons/browserconfig.xml"), name: 'msapplication-config' %>
<%= content_tag :link, nil, href: image_path("favicons/manifest.json"), rel: :manifest %>
Run Code Online (Sandbox Code Playgroud)
用image_path这种方式可以吗?(即使它们不是图像,我已将所有图标文件放在一个文件夹中assets/images/favicons)
此外,xml 和 json 文件都包含对现在位于资产管道中的网站图标图像(见下文)的引用。所以在目前的形式下,这些引用失败了。如何引用 xml 和 json 文件中的图像?
浏览器配置.xml:
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square70x70logo src="/mstile-70x70.png"/>
<square150x150logo src="/mstile-150x150.png"/>
<square310x310logo src="/mstile-310x310.png"/>
<wide310x150logo src="/mstile-310x150.png"/>
<TileColor>#fff8dc</TileColor>
</tile>
</msapplication>
</browserconfig>
Run Code Online (Sandbox Code Playgroud)
清单.json:
{
"name": "AppName",
"icons": [
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Rails Asset Pipeline 来处理 less.erb 文件。
在我使用 LESS 之前,我使用了 SCSS。使用 SCSS 我可以拥有 SCSS.ERB 文件。一切都很完美。
不幸的是,我想使用的 UI 框架 (Semantic-UI) 不支持 SCSS,只支持 LESS。
所以我改变了:
添加了这些宝石:
gem 'less-rails', '~> 2.7.0'
gem 'therubyracer', '~> 0.12.2'
gem 'less-rails-semantic_ui', '~> 2.0.7'
Run Code Online (Sandbox Code Playgroud)
然后我将 _colors.less.erb 文件添加到我的资产管道(在 assets/stylesheets/core/_colors.less.erb 中),内容如下:
@import "variables/_colors.less";
<% colors_list = %w(primary secondary gray green red blue yellow purple orange brown violet pink olive teal) %>
/*--------------------
Background Colors
---------------------*/
<% colors_list.each do |color| %>
.bg-color-<%=color%> { background-color: @color-<%=color%>; }
.bg-color-<%=color%>-darker { background-color: @color-<%=color%>-darker; } …Run Code Online (Sandbox Code Playgroud) asset-pipeline ×10
ruby ×4
heroku ×2
css ×1
erb ×1
less ×1
organization ×1
rails-admin ×1
sass ×1
sprockets ×1