我有几个CSS文件使用相对路径来引用图像url( "../img/my_image.jpg" ).
一切都development在production环境中工作,因为所有CSS文件都打包在一个文件中并且结构丢失,亲戚路径也丢失了,并且找不到图像.
我有这样的资产结构:
/app
/assets
/plugins
/my_plugin
/img
my_image.jpg
/css
my_css.css
Run Code Online (Sandbox Code Playgroud)
(/my_plugin可以是任何一组插件css,js以及images任何其他的Twitter Bootstrap文件)
进入/app/assets/plugins/my_plugin/my_css.css我有类似的东西:
background-image: url("../img/my_image.jpg");
Run Code Online (Sandbox Code Playgroud)
在/app/assets/stylesheets/application.css:
*= require css/my_css.css
Run Code Online (Sandbox Code Playgroud)
最后在head我的html文件中:
<%= stylesheet_link_tag "application" %>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
Mini应用程序重现问题,在README中有安装和重现问题的指令.
如何在不需要重新启动服务器的情况下有效处理生产轨道环境中的更改资产?
我们遇到的问题是,我们必须重新启动运行应用程序的瘦服务器才能提供更新的javascript文件.
现在我们每小时从一些长时间运行的任务生成数据到javascript文件,所以我们可以在我们的Rails应用程序中使用它.
为了清楚起见,我们更新/覆盖现有文件,而不是添加新文件.
生成后,我们运行这些命令以重新预编译所有资产.
bundle exec rake assets:precompile
bundle exec rake rails_group=assets assets:clean RAILS_ENV=production
在清除浏览器缓存并重新加载页面后,我们仍在为旧资产提供服务.
你们有没有做过类似的经历; 你做了什么来解决它?
PS.祝大家节日快乐!
好的,所以在我的css.scss文件中的@import需要扩展名之前我遇到过这个问题:
@import 'layout.css.scss'
Run Code Online (Sandbox Code Playgroud)
代替
@import 'layout'
Run Code Online (Sandbox Code Playgroud)
不知道为什么这只发生在生产中(本地我没有问题).我讨厌必须添加扩展,不知道为什么,我想这只是让我感到烦恼,我必须输入它?:)
我遇到的问题是我似乎无法在生产中使用指南针.我正在使用指南针轨道宝石.我有一个_config.css.scss文件,其顶部有以下导入:
@import "compass";
@import "compass/css3";
Run Code Online (Sandbox Code Playgroud)
我尝试将css.scss添加到它们然后找不到文件(甚至在本地).所以我的问题是这样的:
我有什么方法可以使用@import而不必包含文件扩展名吗?
如果没有,我如何让Compass工作?
这再次影响了我的生产.
我已经尝试了一些我在Stackoverflow上发现的不同的东西,但没有任何帮助.
Rails 3应用程序中的Sass导入错误 - "导入未找到或不可读的文件:指南针"
我在生产中运行应用程序时遇到的确切错误:
Completed 500 Internal Server Error in 920ms
ActionView::Template::Error (File to import not found or unreadable: compass.
Run Code Online (Sandbox Code Playgroud)
UPDATE
我成功地将.scss添加到我的指南针导入中
@import 'compass.scss'
Run Code Online (Sandbox Code Playgroud)
这不再局部抛出"找不到文件"错误.
但在生产中我仍然会收到此错误:
ActionView::Template::Error (File to import not found or unreadable: compass.scss
Run Code Online (Sandbox Code Playgroud)
所以这告诉我,可能我的Compass宝石在生产中无法正常工作?
所以我最近刚刚在一个新项目中安装了Foundation 4.但是,如果我尝试使用foundation_and_overrides.scss文件中定义的变量,则会收到错误消息,指出找不到变量.
例
application.css.scss
/*
*= require_self
*= require foundation_and_overrides
*= require navigation
*/
Run Code Online (Sandbox Code Playgroud)
foundation_and_overrides.scss
@import "foundation/foundation-global";
$topbar-bg: #230F2B;
@import "foundation";
Run Code Online (Sandbox Code Playgroud)
navigation.css.scss
#welcome a:not(.button):hover{
background: $topbar-bg;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误 Undefined variable: "$topbar-bg".
但是覆盖文件的工作方式是顶部栏实际上会改变颜色,但这只是我无法在其他地方使用此变量.
使用Rails 3.2.13我得到不同的资产路径,asset_path取决于我是否使用.css.sass或只是.css这个预期?
例如,如果我app/assets/stylesheets/foo.css.sass在样式表目录中只有一个而没有其他内容,如果我不小心使用asset_pathsass版本,我会得到一个不存在的文件:
Loading production environment (Rails 3.2.13)
irb(main):001:0> helper.asset_path "foo.css.sass"
=> "/assets/foo-b148cf064a02aef053d2902b6a1fa5a9.css"
Run Code Online (Sandbox Code Playgroud)
使用asset_pathjust plain css会产生正确的路径.
irb(main):002:0> helper.asset_path "foo.css"
=> "/assets/foo-1b1fbb65d54bbc52b702c0f1d2efcc38.css"
Run Code Online (Sandbox Code Playgroud)
仅foo-1b1fbb65d54bbc52b702c0f1d2efcc38.css在我运行时生成rake assets:precompile.有谁知道不同的哈希值来自哪里?
我正在运行Rails 4.0.1和Ruby 2.0.0.我目前有一个graph.js,它从用户那里获取一个储蓄计算器的输入,以便用d3和rickshaw.js图创建一个图形.
我的graph.js文件保存在app/assets/javascripts/graph.js.我打电话给人力车图
var graph = new Rickshaw.Graph()
Run Code Online (Sandbox Code Playgroud)
我收到了错误 Uncaught ReferenceError: Rickshaw is not defined.
该rickshaw.js文件vendor/javascript/rickshaw.js与d3.layout.js和一起保存d3.vs.js.如果我保存所有这些文件在app/assets/javascripts一切正常,但这似乎不是正确的rails方式.
有谁知道如何解决这个错误?
谢谢.
我试图在表单中获得一个简单的范围滑块(1-10).
我正在使用'bootstrap-slider-rails'宝石 https://github.com/stationkeeping/bootstrap-slider-rails
几乎花了4个小时,仍然无法让它工作.我可以看到js和css文件加载正常,也没有在控制台中看到任何JS错误
以下是相关的代码段:
在表单页面上:
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}
%meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
%script{:src => "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"}
%script{:src => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"}
%link{href: "//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css", rel: "stylesheet"}/
Run Code Online (Sandbox Code Playgroud)
身体:
%label.control-label Slider
.controls
.input-prepend
%input#slide.span2{"data-slider-max" => "20", "data-slider-min" => "-20", "data-slider-orientation" => "horizontal", "data-slider-selection" => "after", "data-slider-step" => "1", "data-slider-value" => "-14", type: "text", value: ""}/
Run Code Online (Sandbox Code Playgroud)
application.css.scss
*= require jquery.ui.core
*= require jquery.ui.theme
*= require_self
*= require bootstrap-slider
*= require_tree .
*= stub active_admin
*/
Run Code Online (Sandbox Code Playgroud)
的application.js
//= require jquery …Run Code Online (Sandbox Code Playgroud) jquery jquery-ui ruby-on-rails asset-pipeline twitter-bootstrap
我有一个像下面这样的目录结构:
my-app/
.git/
db/ <-- Database stuff
lib/ <-- Business logic
spec/
web/ <-- Rails
Run Code Online (Sandbox Code Playgroud)
Rails位于web/存储库的子目录中.Heroku默认不喜欢这个.
我有一个部分工作的heroku buildpack.它基本上要求在运行任何任务之前Dir.chdir更改为APP_SUBDIR环境变量(如果存在).
我想部署到Heroku,但我无法让资产管道任务工作.在预编译资产时,定制的buildpack将更改为web/目录并尝试运行该任务.
但是,我得到了这个错误,有以下重要的一点:
Could not detect rake tasks
ensure you can run `$ bundle exec rake -P` against your app with no environment variables present
and using the production group of your Gemfile.
Your Ruby version is 1.9.2, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为Heroku清楚地说我在同一个牧场上运行2.0.事实上,当我跑:
$ heroku run 'cd web; bundle …Run Code Online (Sandbox Code Playgroud) 当我在index.html.erb中使用脚本标签时,确切的代码运行正常但是当我将代码放在index.js.erb中时,我收到错误:
Uncaught Rickshaw.Graph needs a reference to an element
Run Code Online (Sandbox Code Playgroud)
我试过预编译资产,真的不知道还有什么可以尝试...
这里也是我的application.js
//= require rickshaw_with_d3
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
我也尝试将人力车放在底部.还不知道以什么顺序装入铁轨中的东西,任何想法?
我需要评论application.js资产pipeleine清单文件中包含的其中一个文件,向清单添加或包含文件的方式是通过清单文件中的注释.例如,需要bootstrap意味着bootstrap.css或bootstrap.js文件分别包含在应用程序的css或javascript资源中.下面是该文件的一个示例
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS file within this directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require main
*= require …Run Code Online (Sandbox Code Playgroud) asset-pipeline ×10
css ×2
jquery ×2
buildpack ×1
compass-sass ×1
deployment ×1
grails ×1
heroku ×1
import ×1
jquery-ui ×1
rickshaw ×1
sass ×1
thin ×1