Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:59:50+00:00 2026-06-13T00:59:50+00:00

Using deploy.rb to precompile rails assets only when they change, this task is always

  • 0

Using deploy.rb to precompile rails assets only when they change, this task is always skipping the compile of my assets 🙁

namespace :assets do
  task :precompile, :roles => :web, :except => {:no_release => true} do
    from = source.next_revision(current_revision)
    if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
      run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
    else
      logger.info "Skipping asset pre-compilation because there were no asset changes"
    end
  end
end

What could causing this complete task not compiling? It always thinks there are no asset changes and throws that message.

I also never really understood the task, for example what does below source.log.local refer to?

source.local.log

Could anyone clarify what the task commands do and has some pointers why it never sees any asset changes? Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:59:51+00:00Added an answer on June 13, 2026 at 12:59 am

    What it does:

    from = source.next_revision(current_revision)
    

    source is a reference to your source code, as seen through your SCM (git, svn, whatever). This sets from as (essentially) the currently deployed version of your source code.

    capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l")
    

    capture means ‘execute this command in the shell, and return its output’. The command in question references the log of changes to your source comparing the deployed version to the current version (specifying the paths where assets live as the ones that ‘matter’), and passes that into the word count tool (wc -l). The -l option means that it returns a count of the number of lines in the output. Thus, the output (which is returned by capture) is the number of filenames that have changes between these two versions.

    If that number is zero, then no files have changed in any of the specified paths, so we skip precompiling.

    Why it doesn’t work:

    I don’t know. There doesn’t seem to be anything wrong with the code itself – it’s the same snippet I use, more or less. Here’s a couple of things that you can check:

    1. Does Capistrano even know you’re using the asset pipeline? Check your Capfile. If you don’t have load 'deploy/assets' in there, deploying won’t even consider compiling your assets.

    2. Have you, in fact, enabled the asset pipeline? Check application.rb for config.assets.enabled = true

    3. Do you have incorrect asset paths specified? The code is checking for changes in vendor/assets/ and app/assets/. If your assets live somewhere else (lib/assets, for instance), they won’t be noticed. (If this is the case, you can just change that line to include the correct paths.

    4. Have you, in fact, changed any assets since the last deployment? I recommend bypassing the check for changed assets and forcing precompile to run once, then turning the check back on and seeing it the problem magically resolves itself. In my example, below, setting force_precompile = true would do that.

    What I use:

    Here’s the version of this I currently use. It may be helpful. Or not. Changes from the original:

    1. A more readable way to specify asset paths (if you use it, remember to set asset_locations to the places your assets live)
    2. An easy way to force precompile to run (set force_precompile=true to attempt to run the check, but run precompile regardless)
    3. It prints out the count whether or not precompile runs. I appreciate getting some output just to be sure the check is running.
    4. If an error occurs when trying to compare the files (as will often happen with brand new projects, for instance), it prints the error but runs precompile anyway.

    .

      namespace :assets do
        task :precompile, :roles => :web, :except => { :no_release => true } do
          # Check if assets have changed. If not, don't run the precompile task - it takes a long time.
          force_compile = false
          changed_asset_count = 0
          begin
            from = source.next_revision(current_revision)
            asset_locations = 'app/assets/ lib/assets vendor/assets'
            changed_asset_count = capture("cd #{latest_release} && #{source.local.log(from)} #{asset_locations} | wc -l").to_i
          rescue Exception => e
            logger.info "Error: #{e}, forcing precompile"
            force_compile = true
          end
          if changed_asset_count > 0 || force_compile
            logger.info "#{changed_asset_count} assets have changed. Pre-compiling"
            run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
          else
            logger.info "#{changed_asset_count} assets have changed. Skipping asset pre-compilation"
          end
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I deploy Django using Gunicorn with the Eventlet worker type, and only use
I'm using Chef to deploy a rails server. I'm storing my code in a
I'm using rubber to deploy a rails application and am having trouble connecting to
Trying to test deploy a simple Rails 3.1 app in production mode, using the
I'm ready to deploy my Rails 3.1 app into production, and since I'm using
I'm using web deploy to a remote server, through which we can only connect
I'm using web deploy to publish my app on production and visual studio always
I am using capistrano to deploy my rails application. I want to override the
I deploy code to my production server using git. This might include changes to
I'm using Capistrano with Rails 3.2.1. When I do cap deploy , I get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.