首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将我的rails应用程序部署到heroku时,CSS样式已损坏

将我的rails应用程序部署到heroku时,CSS样式已损坏
EN

Stack Overflow用户
提问于 2015-05-10 19:52:30
回答 3查看 1.5K关注 0票数 19

我有一个现有的heroku Rails4应用程序(https://applicantlabs.herokuapp.com/),它在本地运行时看起来是正确的,但当我在heroku上运行它时,样式就坏了。

我的gemfile看起来像这样

代码语言:javascript
复制
source 'https://rubygems.org'
ruby "2.2.1"
gem 'rails', '4.2.1'
gem 'pg'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'devise'
gem 'devise-bootstrap-views'
gem "twitter-bootstrap-rails"
gem 'rails_12factor', group: :production # for heroku
gem 'puma'
gem 'sucker_punch'

我尝试通过将此代码添加到config/environments/production.rb文件中,然后部署

代码语言:javascript
复制
config.assets.compile = true

我也试过了

代码语言:javascript
复制
bundle exec rake assets:precompile

然后提交并推动。

什么都不起作用。

css文件将添加到app/assets/stylesheets

然后在app/assets/stylesheets/application.css中,我有

代码语言:javascript
复制
/*
 *= require animate.min
 *= require bootstrap_and_overrides
 *= require font-awesome
 *= require_self
 */
body{padding:0;margin:0;font-family:'Open Sans','Trebuchet MS',arial,sans-serif;font-size:13px}

当我查看页面的源代码并单击css文件时,它充满了奇怪的文本。下面是其中的一小部分:

代码语言:javascript
复制
book����mark����8���8���ìS���

当我推送到heroku时,输出是:

代码语言:javascript
复制
~/Source/applicantlabs> git push heroku master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 483 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.1
remote: -----> Installing dependencies using 1.7.12
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Using rake 10.4.2
remote:        Using minitest 5.6.1
remote:        Using thread_safe 0.3.5
remote:        Using builder 3.2.2
remote:        Using erubis 2.7.0
remote:        Using mini_portile 0.6.2
remote:        Using rack 1.6.0
remote:        Using mime-types 2.5
remote:        Using arel 6.0.0
remote:        Using bcrypt 3.1.10
remote:        Using hitimes 1.2.2
remote:        Using json 1.8.2
remote:        Using orm_adapter 0.5.0
remote:        Using thor 0.19.1
remote:        Using devise-bootstrap-views 0.0.4
remote:        Using execjs 2.5.2
remote:        Using pg 0.18.1
remote:        Using bundler 1.7.12
remote:        Using rails_serve_static_assets 0.0.4
remote:        Using rails_stdout_logging 0.0.3
remote:        Using nokogiri 1.6.6.2
remote:        Using rack-test 0.6.3
remote:        Using warden 1.2.3
remote:        Using puma 2.11.2
remote:        Using sprockets 3.0.3
remote:        Using tzinfo 1.2.2
remote:        Using mail 2.6.3
remote:        Using uglifier 2.7.1
remote:        Using rails_12factor 0.0.3
remote:        Using loofah 2.0.1
remote:        Using i18n 0.7.0
remote:        Using rails-html-sanitizer 1.0.2
remote:        Using timers 4.0.1
remote:        Using celluloid 0.16.0
remote:        Using sucker_punch 1.4.0
remote:        Using activesupport 4.2.1
remote:        Using rails-deprecated_sanitizer 1.0.3
remote:        Using activemodel 4.2.1
remote:        Using rails-dom-testing 1.0.6
remote:        Using activerecord 4.2.1
remote:        Using actionview 4.2.1
remote:        Using globalid 0.3.5
remote:        Using actionpack 4.2.1
remote:        Using activejob 4.2.1
remote:        Using sprockets-rails 2.2.4
remote:        Using railties 4.2.1
remote:        Using jquery-rails 4.0.3
remote:        Using responders 2.1.0
remote:        Using actionmailer 4.2.1
remote:        Using rails 4.2.1
remote:        Using devise 3.4.1
remote:        Using twitter-bootstrap-rails 3.2.0
remote:        Your bundle is complete!
remote:        Gems in the groups development and test were not installed.
remote:        It was installed into ./vendor/bundle
remote:        Bundle completed (0.76s)
remote:        Cleaning up the bundler cache.
remote:        Detected manifest file, assuming assets were compiled locally
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:        Default types for Ruby  -> console, rake, worker
remote: 
remote: -----> Compressing... done, 67.4MB
remote: -----> Launching... done, v38
remote:        https://applicantlabs.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/applicantlabs.git
   697fef0..4cc4ec5  master -> master

如果我运行

代码语言:javascript
复制
bundle exec rake assets:precompile RAILS_ENV=production

输出为

代码语言:javascript
复制
bundle exec rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activerecord-4.2.1/lib/active_record/connection_adapters/connection_specification.rb:171:in `spec'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:50:in `establish_connection'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activerecord-4.2.1/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activerecord-4.2.1/lib/active_record/base.rb:316:in `<module:ActiveRecord>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activerecord-4.2.1/lib/active_record/base.rb:26:in `<top (required)>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1/gems/devise-3.4.1/lib/devise/orm/active_record.rb:3:in `<top (required)>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/grantspilsbury/Source/applicantlabs/config/initializers/devise.rb:22:in `block in <top (required)>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1/gems/devise-3.4.1/lib/devise.rb:293:in `setup'
/Users/grantspilsbury/Source/applicantlabs/config/initializers/devise.rb:3:in `<top (required)>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `call'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
/Users/grantspilsbury/Source/applicantlabs/config/environment.rb:5:in `<top (required)>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/application.rb:328:in `require_environment!'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/railties-4.2.1/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1@global/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/grantspilsbury/.rvm/rubies/ruby-2.2.1/bin/rake:33:in `<main>'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/Users/grantspilsbury/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => environment
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-05-13 20:52:20

bootstrap_and_overrides.css文件中需要字体Awesome,然后在app/assets/stylesheets/application.css中,这个重复导致了一个奇怪的预编译css文件。一旦从app/assets/stylesheets/application.css中删除了*= require font-awesome,就可以正确编译css样式

票数 4
EN

Stack Overflow用户

发布于 2015-05-12 22:55:01

根据我所看到的,您有许多问题需要解决,因为您的问题与CSS有关,我将转到那里:

代码语言:javascript
复制
Mixed Content: The page at 'https://applicantlabs.herokuapp.com/' was loaded over HTTPS, but requested an insecure resource 'http://player.vimeo.com/video/57175742?title=0&byline=0&portrait=0&color=e2007a'. This request has been blocked; the content must be served over HTTPS.
applicantlabs.herokuapp.com/:401 

Mixed Content: The page at 'https://applicantlabs.herokuapp.com/' was loaded over HTTPS, but requested an insecure resource 'http://www.youtube.com/embed/ySJhFCtVTUQ?list=UUvNBXWGykQrWb7kPAn5eLUQ'. This request has been blocked; the content must be served over HTTPS.
application-4ed64624ca6f0911d127cb1a8d49f3c36aedeffcb9f0216df950229bb9db906c.js:13549 

Uncaught TypeError: Cannot read property 'defaults' of undefined
application-4ed64624ca6f0911d127cb1a8d49f3c36aedeffcb9f0216df950229bb9db906c.js:13496 

Uncaught TypeError: Cannot read property 'layoutColors' of undefined application-4ed64624ca6f0911d127cb1a8d49f3c36aedeffcb9f0216df950229bb9db906c.js:13496 

最后两个错误在编译后的资源中。这被标记为未定义:

代码语言:javascript
复制
   colors: mvpready_core.layoutColors

这也被标记为未定义

代码语言:javascript
复制
$.extend( true, DataTable.defaults, {...

编译后的CSS资源结构不正确,数据看起来已损坏。文件名是欢迎-xxx.css,而不是标准的应用程序-xxxxx.css它也充满了损坏的数据,而不是CSS。这是你的CSS:

代码语言:javascript
复制
bookmark88�S`�^�,^��A�SApplicationsMAMPhtdocsmvp-release-2.0.1  mvp-themebower_componentsanimate.cssanimate.min.css $0@\p��)�'7�����l�
m�Xm��n�
o� ���,<LA�ŕ�   file:///���������EE����������E6OXdknnkdXO6ic11o�PNG

现在,作为调试此CSS问题的下一步,我将要求您运行以下命令:

代码语言:javascript
复制
$bundle exec rake assets:precompile RAILS_ENV=production

请张贴其创建的资产的文件名。如果创建了CSS文件,其中包含什么内容?

票数 5
EN

Stack Overflow用户

发布于 2015-05-13 05:17:44

将assets.rb中的Rails.application.config.assets.version =‘1.0’更改为Rails.application.config.assets.version = '1.1‘,这对我很有效

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30151061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档