Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 assets has no fingerprint in production

Just started to adapted to rails 3.1, I started to write coffeescript and sass and everything works fine in development. When I run the server in production, I only get:

  <link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="/javascripts/application.js" type="text/javascript"></script>

in the source code of the page, there's no hashcode generated and both assets has routing errors:

Routing Error
No route matches [GET] "/stylesheets/application.css"

What's the cause of this? Did I forget to do something?

settings in environments/production.rb :

# 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 = false

  # 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

  config.active_support.deprecation = :notify

Thank you very much.

Add more information:

in layouts/application.html.erb, I am using the following to include the assets:

  <%= stylesheet_link_tag "application" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>

And I've tried bundle exec rake assets:precompile which runs without output anything and then run rails s -e production , the problem persists.

And I also tried to set config.assets.compile = true and then run rails s -e production , the problem still persists.

Please help.

More information. I've seen that the compiled js and css are generated in public/assets folder, but in production enviroment, the files are included without the hash code.

Help.

Solution: Just checked again my project, and found that the root cause is when I was editing application.rb for the support of mongodb. I accidentally commented

require "sprockets/railtie"

uncomment it then everything is fine.

Leave this for others to remind my rookie mistake.

Thank you very much Richard. Your answer is not final anwser but it helps a lot, really deserves an up vote.

like image 629
larryzhao Avatar asked Oct 04 '11 13:10

larryzhao


1 Answers

Check that you have the pipeline turned on in application.rb:

config.assets.enabled = true

Are you using the correct helper methods for writing the tags? The helper methods should not have the /styleheets and /javascript in the path. Like this (inside erb):

javascript_include_tag "application"
stylesheet_link_tag "application"

You will also need to run the precompile task as part of the deploy processs to create the files, since you've set compile to false.

The asset pipeline guide shows how to set this up with capistrano.

like image 198
Richard Hulse Avatar answered Nov 09 '22 02:11

Richard Hulse