Rails: How do I do bundle clear? - ruby-on-rails

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.

Related

Hartl Rails tutorial ch. 5 doesn't load bootstrap automatically

At the point in Ch. 5 of the Hartl tutorial where he's showing off CSS/SCSS/Bootstrap styling for the first time (ch. 5.1.2), you're supposed to see the page transformed from an unstyled HTML page to a nifty styled page. But I wasn't seeing the change. It stayed unstyled.
I typed in the listings carefully (and even copied and pasted them from the website, just to be sure, after encountering this problem), tried switching to different gem version numbers (as other advice on similar problems said to do), etc.
Then I decided to insert in my application.html.erb layout the <link> to the Bootstrap CDN, as well as <div class="bootstrap-fluid"> (which I'm glad I learned from FreeCodeCamp) and that fixed the problem:
<head>
...
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
...
</div>
</body>
Apparently I had done nothing wrong otherwise...my guess is that the bootstrap-sass gem (or some other gem) was not supplying this information correctly.
I'm concerned that if I've put this code in my layout, stuff might break later on. Like, it's supposed to work without what I added, right? Any ideas how to make it work the way Hartl wants it to work?
UPDATE: Ugh. Typo! It turns out that I had misnamed custom.css.scss to custom.css.cscc. Well, that'll do it!
The only reason the Bootstrap CDN link helped was that my layout made use of some Bootstrap. When I started adding custom CSS to custom.css.cscc (sic!) I knew the file wasn't even being read. Lesson learned...type even more carefully.

How to tell Rails to not clean some assets in the public folder

The issue here is that I have Bootstrap on production looking for the fonts at:
assets/spree/fonts/glyphicons-the-file-name.something
When in development mode, it looks for these assets in:
fonts/glyphicons-the-file-name.something
So what I did was I added the fonts folder into public and it all worked. I did the same for production. You can guess that I'm now dealing with a rails assets:clean issue that must be running and removing the files, hence not allowing them to appear.
Is there a way to tell Rails to not clean the files in assets/spree/fonts?
I'm assuming you installed the bootstrap files manually?
If you instead use a gem such as the following, then you won't have to worry about these issues:
gem "bootstrap-sass"
Alternatively, you should be installing everything into your vendor directory. As you've found you'll then have issues with any linked assets within these files. The correct fix for this would be to edit the bootstrap source to use the correct asset_path helpers.
Obviously that's quite a bit of maintenance overhead when you get round to doing the next bootstrap update.
I'd take a look at the bootstrap-sass gem, even if you decide not to use it.

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!

File asset fingerprint is not updating correctly on Rails 3.1

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.

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