Heroku上的Ruby on Rails部署 - bootstrap-sass

4

我很困扰如何在Heroku上部署。真的不知道为什么它不能工作。

这是我的Gem文件:

gem 'rails', '3.2.0'
gem 'pg'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
end
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
gem "rspec-rails", ">= 2.8.1", :group => [:development, :test]
gem "factory_girl_rails", ">= 1.7.0", :group => :test
gem "email_spec", ">= 1.2.1", :group => :test
gem "cucumber-rails", ">= 1.3.0", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "database_cleaner", ">= 0.7.1", :group => :test
gem "launchy", ">= 2.0.5", :group => :test
gem "devise", ">= 2.0.4"
gem 'haml-rails', '>= 0.3.4', :group => :development
gem 'bootstrap-sass', '~> 2.0.2'

Heroku日志:

 cache: [GET /] miss 
 /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'         
 vendor/bundle/ruby/1.9.1/gems/railties-3.2.0/lib/rails/rack/log_tailer.rb:14:in `call'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

简单的应用程序布局

%html
  %head
  %title iPinTeam
  %meta{:charset => "utf-8"}
  %meta{"http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1"}
  %meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
  %meta{:content => "", :name => "description"}
  %meta{:content => "", :name => "author"}
  = stylesheet_link_tag :application, :media => "all"
  = javascript_include_tag :application
  = csrf_meta_tags
%body{:class => params[:controller]}
 .navbar.navbar-fixed-top
  .navbar-inner
    .container
    = render 'shared/navigation'
#container.container
  #main{:role => "main"}
    - flash.each do |name, msg|
      = content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) 
    = yield
%footer

非常抱歉,如果我的问题显得很愚蠢,我有点困惑为什么会出现这个错误:( 在日志中也有许多错误:

vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.0
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.0
etc...

在Heroku上仍存在问题 - 我们很抱歉,但出现了一些问题。

认为问题可能与Heroku上的gem bootstrap-sass有关。我已经尝试切换到thin web服务器,但情况非常混乱:( 有人可以帮助我解决这个问题,并可能稍微描述一下错误。如果需要额外的信息,我会立即发布。谢谢...


你是否预编译你的资源?如果没有,请先进行预编译,然后再部署。可能更多的日志信息会有用。 - Amar
6个回答

10

在上传到 Heroku 之前,您需要预编译您的资产。

尝试运行 rake assets:precompile,然后上传到 Heroku。


6

我无法在Heroku上查看使用Bootstrap CSS的网站,所以我在config/environments/production.rb中做了以下更改,将该行更改为:

config.assets.compile = false

致:

config.assets.compile = true

3
  • rake assets:precompiled
  • config.assets.initialize_on_precompile = false ..... 所有这些方法对我来说都不起作用。

这种方式适合我: 进入 config/environment/production.rb

将: config.assets.compile = false

改为: config.assets.compile = true


3

与其他答案的资产编译主题相同,Heroku还要求在您的config/application.rb中包含以下行:

config.assets.initialize_on_precompile = false

我相信如果你这样做,就不需要在Cedar堆栈上部署之前运行rake assets:precompile(至少我没有必要这样做)。

更新

我想补充一下,因为我也使用了一些需要我在application.rb中设置config.assets.initialize_on_precompile = true的gems,所以我通常需要在手动部署到Heroku之前预编译我的资产。然而,在运行
$ heroku labs:enable user-env-compile -a HEROKU_APP_NAME (参考)之后,
我不再需要运行rake assets:precompile,Heroku为我编译了资产。我只希望Heroku能够保持这种功能。


2

1
尝试这个。
https://www.bootstrapcdn.com

我只是包含那些链接,这对我来说很好用。 对我来说,这是一个不错的解决方案。
此外,我使用:
1. rake assets:precompile; 2. config.assets.compile = true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接