我刚从Ruby on Rails 3.0.10切换到3.1.0,我使用的是jQuery UI 1.8.14.我在远程计算机上css以生产模式加载文件时遇到问题.
在我的app/views/layouts/application.html.erb档案中,我有:
<%= stylesheet_link_tag 'application', 'jquery-ui-1.8.14.custom', 'jquery-ui-1.8.14.custom_redefinition' %>
<%= javascript_include_tag 'application' %>
Run Code Online (Sandbox Code Playgroud)
注意:该jquery-ui-1.8.14.custom文件是使用Theme Roller生成的CSS文件,jquery-ui-1.8.14.custom_redefinition是我的"自定义重定义"文件,它覆盖了一些CSS类.这些文件(都带有扩展名.css)位于vendor/assets/stylesheets.
在我的本地机器上的开发模式似乎都工作,但当我使用Capistrano部署到远程机器时,它不再起作用.也就是说,jQuery UI相关文件未按预期加载:如果我尝试访问它们,则它们的内容为空\空(我可以在为我的应用程序网页生成的源HTML代码中看到).
我怎么解决这个问题?
此时在我的config/environments/production.rb文件中我有:
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
#
# Note: Since, at this time, the asset Pipeline doesn't work for me I am
# …Run Code Online (Sandbox Code Playgroud) ruby deployment ruby-on-rails ruby-on-rails-3 asset-pipeline
Rails 3.1在开发过程中加载页面非常慢.它通过管道一次一个地处理它们,并且需要太长时间.
是否可以预编译我的资产(我现在没有测试,所以静态文件很好)并且让Rails不负责为它们提供服务?这会让事情变得更快吗?
更新:有一个解决方案.
Richard Hulse对这个问题有正确的答案.rake assets:precompile将预先建立资产,以便直接提供资产,而无需资产管道.
但Frexuz的答案解决了我一直在缓慢加载的问题.加载Rails-dev-tweaks gem可以显着加快开发中的页面加载速度.
所以我想知道的是以下是否可行.我有一个网站,我们使用标准的I18n gem进行国际化(在config/locales/*.yml中有翻译).目前我们依靠各种(非常不优雅的)修复来获取javascript以获取翻译的单词(主要通过使用HTML5数据属性).既然我们已经将我们的站点升级到Rails 3.1,并且我们喜欢新的资产管道,那么如果我们能够将我们的js文件国际化,那就更好了,如下所示:
应用程序/资产/ jsfile.js.erb
alert(<%= I18n.t('javascript.key.name') %>)
Run Code Online (Sandbox Code Playgroud)
然后获取资产管道迭代文件以生成public/assets/jsfile.en.js,public/assets/jsfile.de.js等等(我猜测一个语言环境javascripts_include_tag也很有用)
有没有人知道任何可以做这种工作的例子/宝石/插件,或者是时候破解IDE并开始自己编写代码?
javascript internationalization ruby-on-rails-3.1 asset-pipeline
我在heroku上为我的应用程序设置了2个环境:分段和生产,我正在使用Rails 3.1资产管道.
我已经设置了一个自定义的config.action_controller.asset_host属性,以便在http://assets.myapp-staging.com或http://assets.myapp.com上从cloudfront获取我的资产.
问题是,在Heroku上,资产总是与生产环境一起预编译.这意味着即使在分段中,我的css或js文件中存在的所有URL都以http://assets.myapp.com为目标.
任何的想法?
我试图预编译资产(rake assets:precompile或bundle exec rake assets:precompile),但我总是得到错误
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Access denied for user 'root'@'localhost' (using password: YES)
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/adam/.rvm/rubies/ruby-1.9.2-p290/b...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
有谁知道什么可能是错的?
编辑跟踪输出
rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/adam/.rvm/gems/ruby-1.9.2-p290/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** …Run Code Online (Sandbox Code Playgroud) 有没有办法在JavaScript public文件之前从文件夹加载JavaScript assets/javascript?
我在Ruby on Rails网站上使用bootstrap-sass gem.我想让我的布局响应,所以我尝试添加@import "twitter/bootstrap/responsive"到各种文件,但我得到的只是一条消息说:
要导入的文件未找到或不可读:bootstrap/responsive.加载路径:Sass :: Rails :: Importer(site_path/app/assets/stylesheets/bootstrap_and_overrides.css.scss)
ruby-on-rails asset-pipeline responsive-design twitter-bootstrap
我有上述错误.我已经看到很多问题,答案是"重启rails服务器".但这不是我的情况,因为这不是rails服务器错误.
由于我的项目在Heroku中工作得不好(下拉列表不能正常工作),但是在本地环境中我做得非常好,我正在尝试在部署之前编译所有资产,bundle exec rake assets:precompile但它会抛出错误:
~/.rvm/rubies/ruby-1.9.3-p448/bin/ruby ~/.rvm/gems/ruby-1.9.3-p448@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
File to import not found or unreadable: mycustom.scss.
Load path: ~/RubyProjects/sample_app_2
(in ~/RubyProjects/sample_app_2/app/assets/stylesheets/application.css)
Run Code Online (Sandbox Code Playgroud)
我认为这是一个sass问题,所以我运行bundle exec sass app/assets/stylesheets/mycustom.scss
但它会抛出错误:
Syntax error: File to import not found or unreadable: bootstrap
Load path: ~/RubyProjects/sample_app_2
Run Code Online (Sandbox Code Playgroud)
所以我认为问题是引导程序不包含在项目的某个地方.因为如果我跑
bundle exec sass ~/.rvm/gems/ruby-1.9.3-p448@scaffold-example/gems/bootstrap-sass-2.0.0/vendor/assets/stylesheets/_bootstrap.scss
Run Code Online (Sandbox Code Playgroud)
它显示了4000多行的CSS.
难道我做错了什么?
我应该做点别的吗?
这是我的Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'sass-rails', '3.2.4'
#gem 'bcrypt-ruby', '3.1.1.rc1', :require => 'bcrypt'
#gem 'bcrypt-ruby', '3.1.0', :require => 'bcrypt' …Run Code Online (Sandbox Code Playgroud) 我正在使用image_path进入我的控制器:
class ArchivesController < ApplicationController
include ActionView::Helpers::AssetUrlHelper
def create
@archive = Archive.new(file: params[:file])
render json: {ico: image_path('docs/pdf.png')}
end
end
Run Code Online (Sandbox Code Playgroud)
但我的回归是{ico: '/images/docs/pdf.png'}.
当我image_path('docs/pdf.png')在我的视图中使用时,网址为'/docs/pdf.png'并且有效.
为什么在我的控制器中网址不同?
在生产服务器上进行预编译时出现错误;但是,如果我将环境设置为生产环境并在开发计算机上运行预编译,则运行正常。怎么可能呢?
RAILS_ENV="production" bundle exec rake assets:precompile RAILS_GROUPS=assets
Run Code Online (Sandbox Code Playgroud)
返回错误:
...
rake aborted!
ExecJS::RuntimeError:
(execjs):1
...
Run Code Online (Sandbox Code Playgroud)
我根本不知道错误是从哪里来的。
asset-pipeline ×10
ruby ×2
assets ×1
deployment ×1
heroku ×1
javascript ×1
jquery ×1
maskedinput ×1
performance ×1
precompile ×1
sass ×1
sprockets ×1