nbkincaid
nbkincaid

Reputation: 127

heroku - rails 3.1 - asset pipeline

I've been struggling with this for some time now and I just can't find a post that has as simple of a problem as mine. I am new to working with Heroku and Rails and am trying to figure out how to get asset pipeline to work with a css file that I have in the "App/assets/stylesheets" directory. I've tried following posts from http://guides.rubyonrails.org/asset_pipeline.html and http://www.youtube.com/watch?v=p_3dIPgXgkg, but I can't figure out how to get Heroku to deploy a very simple site with a new css file. I've verified that asset pipeline is the issue by disabling the pipeline and Heroku deploys it just fine. My local server employs the css just fine, so the problem must be my settings with the asset pipeline.

I have created a new css file at the following location: "app/assets/stylesheets/custom.css"

Here is what the contents of the manifest file look like at "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 . 
*/

Here is what my "config/application.rb" file looks like:

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


I am using "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]" on "Rails 3.1.3"

And finally, here is a look at my 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'



Can anybody help me out with this one? Thank you, Nicholas Kincaid

Here is the output from j_mcnally's request:

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 [email protected]:strong-moon-9939.git
   95351fa..8e4131f  master -> master


Here's what the heroku logs messages give me:

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

Upvotes: 0

Views: 1009

Answers (3)

nbkincaid
nbkincaid

Reputation: 127

Okay, I finally figured this one out. After looking through http://guides.rubyonrails.org/asset_pipeline.html some more, I realized that I needed to add in:

//= require custom

to the application.css file. I entered this outside of comments and this fixed my problem. I was able to precompile locally and everything worked perfectly on Heroku after that. Thank you to everybody that helped me get there.

Upvotes: 0

Mgrandjean
Mgrandjean

Reputation: 317

So I'm not sure, but it could be that you've deployed to the wrong Heroku environment. In order to use the asset pipeline, rails 3.1 stuff you have to have made a heroku cedar environment. see the heroku site for details

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

quote from that website

While Rails 3.1 and 3.2 can run on the Bamboo stack without the asset pipeline, these versions of Rails runs best on Heroku’s Cedar stack. For new users, we recommend reading our tutorial for creating a Rails 3.0 app on Cedar before proceeding further.

Upvotes: 2

j_mcnally
j_mcnally

Reputation: 6968

Add this to application.rb

config.assets.initialize_on_precompile = false

Upvotes: 1

Related Questions