File asset fingerprint is not updating correctly on Rails 3.1 - ruby-on-rails

In my rails 3.1 app, while deploying, the assets is compiled and gets uploaded successfully.
When I visit the app, the css and js files are referenced but the server give back 404.
<link href="/assets/application-f997bad128b3d8a92ed5619470851dab.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/application-d7eac22b3bc8b4e3620abb21f59a5faa.js" type="text/javascript"></script>
Looking on the server, the fingerprint that is printed on the html markup doesn't match so the server returns 404.
But I wonder how the hell this happens.
So, what are the factors that change the fingerprinting of the manifest files?

Maybe your server wasn't reloaded. I've experienced this issue when Unicorn didn't switch over after sending the USR2 signal to the process. I had to manually kill and restart the process to get it going again.

Related

Rails 4: favicon not showing

My favicon just won't show, in Chrome or Firefox. This is how I am rendering it in the <head> section:
<%= favicon_link_tag 'favicon.ico' %>
It is located in public/images.
This is the produced HTML:
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
Opening the link in my browser shows the icon correctly.
The favicon is not handled by the asset pipeline when its in the public folder, and this can cause caching problems.
See here: How to add favicon in rails 3.2 and Clear the cache from the Rails asset pipeline.
Use the favicon_link_tag and place the .ico file in /app/assets/images/ to get it into the asset pipeline.
If it still doesn't work after that, try clearing your browser cache, your rails cache, and restarting your rails server.

What is a good fallback for when MVC Bundling Fails?

In production an MVC site occasionally ends up with a broken bundle:
<link href="/bundles/css/global.css?v=" rel="stylesheet" />
<script src="/bundles/js/combined.js?v="></script>
Recycling the site will regenerate the bundles and make it work again.
At this stage, I'm not too concerned with the why, more what can be done as a fallback for when the bundle generation fails.
The bundles are created thusly (js):
bundles.Add(new ScriptBundle("~/bundles/js/combined.js").Include(
"~/js/file1.js",
"~/js/file2.js",
"~/js/file3.js"));
css:
bundles.Add(new StyleBundle("~/bundles/css/global.css").Include(
"~/css/file1.css",
"~/css/file2.css"));

Rails pages are linking in non-existent css file when using Stylus

I am trying to use Stylus with a Rails 4 project, but the asset pipeline seems to be naming the compiled CSS wrong and/or linking to the wrong file. If I generate some assets (rails g assets static_pages) the served pages all end up trying to link to a file that doesn't exist:
<link data-turbolinks-track="true" href="/assets/static_pages.css?body=1" media="all" rel="stylesheet" />
I'm using the stylus gem and I've removed the default one for SASS from my Gemfile. I've also tried stylus_rails, but that seems to be deprecated and it didn't change anything anyways. Has anyone else encountered this issue when using stylus with rails?
I'm really at a loss here; any help would be appreciated. Thanks!

Rails: How do I do bundle clear?

I inherited a Rails 3.1 app, served by passenger/nginx.
I thought I had to upgrade from ActiveAdmin 0.4 to 0.5, but
that caused other problems, so I found a workaround and
downgraded to 0.4.0.
Then Ruby started complaining that the formtastic-bootstrap
gem wasn't checked out. Here's the line in the Gemfile:
gem 'formtastic-bootstrap', :git => "git://github.com/cgunther/formtastic-bootstrap.git", :branch => "bootstrap-2"
And there certainly was a f-b gem in the config, but then
someone on stackoverflow said to run
bundle install --deployment
and after I ran that incantation, the site loaded. Except all the
ActiveAdmin CSS is gone. I can make small mods to the file
assets/active_admin.css and they take effect, but the site otherwise
looks like times roman crap.
So I did something bad during one of the above steps -- I normally
run bundle install as root, but the site is owned by 'web'.
And after Ruby complained that it couldn't find formtastic-bootstrap,
I found two of those gems installed in /home/web/.bundler/ruby/
(or something like that), and because Ruby must have been complaining
about them, I deleted them. There wasn't anything else there.
After running another bundle install,
the site would then load, but the CSS wasn't taking effect.
I loaded up the reference site in a different tab, and compared the HTML
I've generated with the reference HTML. The only difference is in the
two lines that load the JS and CSS. In the reference site:
<link href="/assets/active_admin-e1b0dc3ef3753e264638b07b12174adb.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/active_admin-385197d3f18a204049d4eb22bc9a033e.js" type="text/javascript"></script>
In mine:
<link href="/assets/active_admin.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/active_admin.js" type="text/javascript"></script>
I know the JS and CSS are being loaded, because I see the alert, and other things get
colorized, just not the ActiveAdmin elements. But the DOM inspector shows that the
reference site is pulling all sorts of things out of that CSS file for the body element,
while for my page, it's only pulling generic style rules out of
resource://gre-resources/html.css and a data URI that doesn't need repeating here.
The Error Console is full of the usual jquery and google.maps JS admonitions (it's
a gmap app), but nothing jumps out.
Does this ring a bell for anyone? I gather the reason why I'm seeing untagged
CSS and JS file references is because of that "bundle install --deployment" I
ran, followed by "bundle install --no-deployment" when things got worse. I just
want to set things back to square 1.
So how can I just clear everything? Or better still, is are there a bunch of
magic doodads being cached somewhere?
You could try doing a bundle uninstall
another possibility is to rename the Gemfile.lock and rerunning bundle install, this will force a full re-install.
If you are using version control, such as Git, you could run a diff and see what changes have been made to the code and comparing.

Rails 3 project, installed jquery-rails gem, but getting "Ajax is not defined"

I'm a rails newbie trying to follow a howto on how to perform some Ajax calls (after switching to jQuery), but I've run into a problem.
Whenever I trigger the ajax code (new Ajax.Request()), I get "Ajax is not defined" in firebug. Anyone with more skills than me know what's up here?
update:
For anyone else having this problem, the code that was generating the the above code, was a call to remote_function()
What I have done to set things up:
Added "gem 'jquery-rails', '>= 1.0.12'" to my gemfile, and run bundle install
Run rails generate jquery:install
My public/javascripts/ folder thus has the following files:
application.js
jquery.min.js
jquery-ui.min.js
jquery.js
jquery-ui.js
jquery_ujs.js
The scripts included in my HTML look like this:
<script src="/javascripts/jquery.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery-ui.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/application.js?1312911234" type="text/javascript"></script>
I'd guess that your tutorial uses Prototype as Ajax.Request is for Prototype, you should be using $.ajax with jQuery. And switching to a jQuery based tutorial might be a good idea too.
You say that you're using remote_function but that's Prototype-specific:
Usage
To be able to use these helpers, you must first include the Prototype JavaScript framework in your pages.
Prototype used to be the default JavaScript library for Rails so I suspect that PrototypeHelper is a leftover. You probably want to look at things like the :remote option on link_to and similar for new code.

Resources