Ruby On Rails: Production / Staging : When asset path is outdated or latest changes in .js or .css is not reflecting

Scenario:

You have just updated an asset ( may be image file or script or stylesheet ), committed that and deployed that change to production or staging or qa or uat server.

Problem:

For example: in case of image asset you have only edited the image may be added an icon in an sprite-image. You see that in browser no icon is rendered. When you inspect the DOM you see the URL is outdated. You know the URL is outdated because you have checked the Asset-precompile manifest your_app/current/public/assets/manifest-[digest].json  in the server which looks like

"radiobutton.png":"radiobutton-7b4ebeb557e1c6f7bd0318dddf8c30a5.png"
"rating.png":"rating-b35838ad4f322dac3f7a58af9e23b038.png"
"sprite-add.png":"sprite-add-2e3bf15cb765b03fb86c41a9108fd360.png"
"sprite-icon.png":"sprite-icon-7e92af7a99b7f6809bb597a257c344cb.png"
"sprite.png":"sprite-8cdd1976f591e6588ab579177a6a3f47.png"
"star.png":"star-2e08bde0ace01b6cf05ae1334750dd88.png"
"tick.png":"tick-c7aeac2132c7dd3e2bbd3e1a3cb0ff00.png"
Inspection of not rendered image in production

Inspection of not rendered image in production

Reason:

After you have deployed your rails server might not be restarted or some thing happened and your rails server failed to load new asset-manifest in memory by looking which Rails maps the asset requests.

Solution:

Deploy your application again

if still not solved

  • SSH into the system delete the file your_app/manifest_backup
  • $ bundle exec rake assets:clear
  • $ bundle exec rake assets:precompile RAILS_ENV=production
  • restart the webserver ( for Nginx /etc/init.d/nginx restart or $ sudo service nginx restart )
  • if still not solved deploy your app again

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s