在部署后链接自定义CSS和Javascript到Rails [英] Link Custom CSS and Javascript to Rails After Deployment
问题描述
< link href = assets / bootstrap.css =stylesheet>
< link href =assets / bootstrap-responsive.css =stylesheet>
< link href =assets / font-awesome.css =stylesheet>
< link href =assets / bootswatch.css =stylesheet>
我Googled比我应该找到的更多这个 Heroku指南,我很困惑关于资产管道的事情!我也运行这个命令:
bundle exec rake assets:precompile
pre>
它在公共目录中创建了一些文件,如指南中所述:
一切都很简单,没有设计没有Css和JS。
当我运行
Heroku Logs
这是我得到一些严重的NO路由匹配CSS和JS文件如下: p>
2013-06-10T10:06:28.184255 + 00:00应用程式[web.1]:ActionController :: RoutingError ]/assetscv.png):
这只是一行,我收集了更多的其他文件,预先生成的loggs行
任何帮助将不胜感激。
PS:
我尝试了
<%= stylesheet_link_tagbootstrap%&
<%= stylesheet_link_tagbootstrap-responsiv%>
<%= stylesheet_link_tagbootswatch,font-awesome.css%>
我遇到了一堆错误,并在heroku上说对不起。
解决方案在application.rb(config / application.rb)
#启用资产管道
config.assets.enabled = true
在production.rb文件(config / environments / production.rb)做这样
#这里指定的设置将优先于那些在config / application.rb
#代码不会在请求之间重新加载$ b $ b config.cache_classes = true
#完全错误报告被禁用,缓存被打开
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
#禁用Rails的静态资产服务器(Apache或nginx已经这样做)
#config.serve_static_assets = true
#压缩JavaScript和CSS
config.assets.compress = true
#如果预编译的资产缺失,不要回退到资产管道
config.assets.compile = false
#为资产网址生成摘要
config.assets.digest = true
那么你应该像这样包含所有的js和css:
config .assets.precompile + =%w(jquery.js jquery_ujs.js PIE.js check_list.js dom-drag.js jquery-1.4.2.min.js jquery-1.7.1.min.js jquery-1.8.3。 js jquery-ui.js jquery.accordion.js jquery.corner.js jquery.countdown.js jquery.dimensions.js jquery.masonry.min.js jquery.tinycarousel.min.js jquery.validationEngine-en.js jquery.validationEngine .js questionnaire.js prototype.js users.js)
config.assets.precompile + =%w(ie7.css ie8.css about_us.css admin_menu.css blog.css default.ultimate.css designer_directory.css designer_directorynew.css drop.css greenstore.css menu.css MenuMatic_dev.css message_view.css product.css setting1.css style1.css styles.css validationEngine.jquery.css)
之后使用此命令预编译
$ RAILS_ENV = production bundle exec rake assets:precompile
然后
$ heroku restart $
有关更多详情,请参阅 http://guides.rubyonrails.org/asset_pipeline.html
I have a Rails App it's css and js links works fine locally since I have used :
<link href="assets/bootstrap.css" rel="stylesheet"> <link href="assets/bootstrap-responsive.css" rel="stylesheet"> <link href="assets/font-awesome.css" rel="stylesheet"> <link href="assets/bootswatch.css" rel="stylesheet">
I Googled more than it should all I find is this Heroku Guide , I'm so confused about the assets pipeline thing! I ran this command as well :
bundle exec rake assets:precompile
and it did create some files in the public dir as mentioned in the guide :
Now on Heroku Everything is plain, no design no nothing of Css and JS.
While when I run
Heroku Logs
This is what I get some serious NO Route Match for the CSS and JS files as follow :
2013-06-10T10:06:28.184255+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assetscv.png"):
This is only one line, I get bunch of more of these for other files, and pre generated loggs lines
any help would be appreciated Thanks!
PS:
I tried
<%= stylesheet_link_tag "bootstrap" %> <%= stylesheet_link_tag "bootstrap-responsiv" %> <%= stylesheet_link_tag "bootswatch", "font-awesome.css" %>
I got bunch of errors and on heroku it says sorry something went wrong
解决方案In application.rb(config/application.rb)
# Enable the asset pipeline config.assets.enabled = true
After this in production.rb file(config/environments/production.rb) do like this
# Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) #config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true
then you should include all your js and css like this,
config.assets.precompile += %w(jquery.js jquery_ujs.js PIE.js check_list.js dom-drag.js jquery-1.4.2.min.js jquery-1.7.1.min.js jquery-1.8.3.js jquery-ui.js jquery.accordion.js jquery.corner.js jquery.countdown.js jquery.dimensions.js jquery.masonry.min.js jquery.tinycarousel.min.js jquery.validationEngine-en.js jquery.validationEngine.js questionnaire.js prototype.js users.js) config.assets.precompile += %w(ie7.css ie8.css about_us.css admin_menu.css blog.css default.ultimate.css designer_directory.css designer_directorynew.css drop.css greenstore.css menu.css MenuMatic_dev.css message_view.css product.css setting1.css style1.css styles.css validationEngine.jquery.css)
After that precompile using this command
$ RAILS_ENV=production bundle exec rake assets:precompile
Then
$ heroku restart
It should work.
For more details please read http://guides.rubyonrails.org/asset_pipeline.html
这篇关于在部署后链接自定义CSS和Javascript到Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!