heroku - rails 3.1 - 资产管道

时间:2012-02-24 06:31:30

标签: ruby-on-rails heroku asset-pipeline

我一直在努力解决这个问题已经有一段时间了,我找不到像我这样简单问题的帖子。我是新手与Heroku和Rails一起工作,我正在试图弄清楚如何让资产管道与我在“App / assets / stylesheets”目录中的css文件一起工作。我已尝试关注来自http://guides.rubyonrails.org/asset_pipeline.htmlhttp://www.youtube.com/watch?v=p_3dIPgXgkg的帖子,但我无法弄清楚如何让Heroku使用新的css文件部署一个非常简单的网站。我已经通过禁用管道来验证资产管道是问题,Heroku部署它就好了。我的本地服务器使用css就好了,所以问题必须是我对资产管道的设置。

我在以下位置创建了一个新的css文件:“app / assets / stylesheets / custom.css”

以下是清单文件的内容在“app / assets / stylesheets / application.css”:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. 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_self
 *= require_tree . 
*/

以下是我的“config / application.rb”文件:

require File.expand_path('../boot', __FILE__)


# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module MegaProject
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
  end
end


我在“Rails 3.1.3”上使用“ruby 1.9.2p290(2011-07-09修订版32553)[x86_64-darwin11.1.0]”

最后,我们来看看我的Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'jquery-rails'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

group :production do
  gem 'pg'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'



有人可以帮我解决这个问题吗?谢谢Nicholas Kincaid

以下是j_mcnally请求的输出:

Nicholass-MacBook-Pro:mega_project nbkincaid$ git push heroku master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 513 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)

-----> Heroku receiving push
-----> Removing .DS_Store files
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
       Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
       Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
       Unresolved dependencies detected; Installing...
       Using --without development:test
       Fetching source index for http://rubygems.org/
       Installing rake (0.9.2.2) 
       Installing multi_json (1.1.0) 
       Installing activesupport (3.1.3) 
       Installing builder (3.0.0) 
       Installing i18n (0.6.0) 
       Installing activemodel (3.1.3) 
       Installing erubis (2.7.0) 
       Installing rack (1.3.6) 
       Installing rack-cache (1.1) 
       Installing rack-mount (0.8.3) 
       Installing rack-test (0.6.1) 
       Installing hike (1.2.1) 
       Installing tilt (1.3.3) 
       Installing sprockets (2.0.3) 
       Installing actionpack (3.1.3) 
       Installing mime-types (1.17.2) 
       Installing polyglot (0.3.3) 
       Installing treetop (1.4.10) 
       Installing mail (2.3.0) 
       Installing actionmailer (3.1.3) 
       Installing arel (2.2.2) 
       Installing tzinfo (0.3.31) 
       Installing activerecord (3.1.3) 
       Installing activeresource (3.1.3) 
       Installing coffee-script-source (1.2.0) 
       Installing execjs (1.3.0) 
       Installing coffee-script (2.2.0) 
       Installing rack-ssl (1.3.2) 
       Installing json (1.6.5) with native extensions 
       Installing rdoc (3.12) 
       Installing thor (0.14.6) 
       Installing railties (3.1.3) 
       Installing coffee-rails (3.1.1) 
       Installing jquery-rails (1.0.19) 
       Installing pg (0.13.1) with native extensions 
       Using bundler (1.0.7) 
       Installing rails (3.1.3) 
       Installing sass (3.1.15) 
       Installing sass-rails (3.1.5) 
       Installing sqlite3 (1.3.5) with native extensions 
       Installing uglifier (1.2.3) 
       Your bundle is complete! It was installed into ./.bundle/gems/
-----> Compiled slug size is 7.0MB
-----> Launching... done, v27
       http://strong-moon-9939.heroku.com deployed to Heroku

To git@heroku.com:strong-moon-9939.git
   95351fa..8e4131f  master -> master


以下是heroku日志消息给我的内容:

2012-02-24T06:57:43+00:00 heroku[router]: GET strong-moon-9939.heroku.com/ dyno=web.1 queue=0 wait=0ms service=7ms status=500 bytes=728
2012-02-24T06:57:43+00:00 heroku[nginx]: 24.13.158.102 - - [24/Feb/2012:06:57:43 +0000] "GET / HTTP/1.1" 500 728 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11" strong-moon-9939.heroku.com
2012-02-24T06:58:38+00:00 app[web.1]: 
2012-02-24T06:58:38+00:00 app[web.1]: 
2012-02-24T06:58:38+00:00 app[web.1]: Started GET "/" for 24.13.158.102 at 2012-02-23 22:58:38 -0800
2012-02-24T06:58:38+00:00 app[web.1]:   Processing by UsersController#home as HTML
2012-02-24T06:58:38+00:00 app[web.1]: Rendered users/home.html.erb within layouts/application (0.0ms)
2012-02-24T06:58:38+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2012-02-24T06:58:38+00:00 app[web.1]: 
2012-02-24T06:58:38+00:00 app[web.1]: ActionView::Template::Error (custom.css isn't precompiled):
2012-02-24T06:58:38+00:00 app[web.1]:     3: <head>
2012-02-24T06:58:38+00:00 app[web.1]:     4:   <title><%= title %></title>
2012-02-24T06:58:38+00:00 app[web.1]:     5:   <%= stylesheet_link_tag "application" %>
2012-02-24T06:58:38+00:00 app[web.1]:     6:   <%= stylesheet_link_tag "custom" %>
2012-02-24T06:58:38+00:00 app[web.1]:     7:   <%= javascript_include_tag "application" %>
2012-02-24T06:58:38+00:00 app[web.1]:     8:   <%= csrf_meta_tags %>
2012-02-24T06:58:38+00:00 app[web.1]:     9: </head>
2012-02-24T06:58:38+00:00 app[web.1]:   app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__150896894354786412_13162880'
2012-02-24T06:58:38+00:00 app[web.1]: 
2012-02-24T06:58:38+00:00 app[web.1]: 
2012-02-24T06:58:38+00:00 app[web.1]: cache: [GET /] miss
2012-02-24T06:58:38+00:00 heroku[router]: GET strong-moon-9939.heroku.com/ dyno=web.1 queue=0 wait=0ms service=7ms status=500 bytes=728
2012-02-24T06:58:38+00:00 heroku[nginx]: 24.13.158.102 - - [24/Feb/2012:06:58:38 +0000] "GET / HTTP/1.1" 500 728 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11" strong-moon-9939.heroku.com

3 个答案:

答案 0 :(得分:2)

所以我不确定,但可能是你已经部署到了错误的Heroku环境。为了使用资产管道,rails 3.1你必须创建一个heroku雪松环境。有关详细信息,请访问heroku网站

http://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar

引用该网站

  

虽然Rails 3.1和3.2可以在没有资产管道的Bamboo堆栈上运行,但这些版本的Rails在Heroku的Cedar堆栈上运行得最好。对于新用户,我们建议您阅读我们在Cedar上创建Rails 3.0应用程序的教程,然后再继续。

答案 1 :(得分:1)

将此添加到application.rb

config.assets.initialize_on_precompile = false

答案 2 :(得分:0)

好的,我终于想出了这个。在仔细查看http://guides.rubyonrails.org/asset_pipeline.html之后,我意识到我需要添加:

//= require custom

到application.css文件。我在评论之外输入了这个,这解决了我的问题。我能够在本地进行预编译,之后一切都在Heroku上完美运行。感谢所有帮助我实现目标的人。