Ruby on Rails - My Micromount database revisited

February 16, 2018

I have not run this in some time, and sure enough, when I type "rails server" to launch this rails app, I throws a fit. I know now to expect this. I hate rails. I am sorry I ever heard of it and had anything to do with it. But I don't have time right now to migrate off of it (but I will, I will!!.)

So let's see how much trouble it is to fix the current set of problems.

I went through this exercise last in July of 2017, just for the record. The first thing I am confronted with is:

Could not find json-1.8.6 in any of the sources
Run `bundle install` to install missing gems.
So I run "bundle install" and try "rails server" again, now I get:
/home/tom/.gem/ruby/gems/activesupport-4.1.9/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
/home/tom/.gem/ruby/gems/activesupport-4.1.9/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
/home/tom/.gem/ruby/gems/activesupport-4.1.9/lib/active_support/core_ext/numeric/conversions.rb:125:in `block (2 levels) in ': stack level too deep (SystemStackError)
from /home/tom/.gem/ruby/gems/activesupport-4.1.9/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in '
A quick Google search indicates that as of ruby 2.4 there was a unification of integer types, making Fixnum and Bignum the same thing (namely Integer). Of course this breaks older gems (such as activesupport apparently). So my options are to either find some way to run some older version of ruby in the 2.3 vintage, just for the sake of this accursed rails project, or move forward from rails 4.1.9 on which this project was developed.

Fix Fedora gem issue

Before I dive into the rails upgrade, I also have another issue when I try to run plain old ruby scripts from the command line. I get messages like:

Ignoring psych-2.0.17 because its extensions are not built.  Try: gem pristine psych --version 2.0.17
I did something drastic here. Namely from my home directory: rm -rf .gem. That seemed to solve the problem of weird warnings from the command line. I will rediscover any gems I need and deal with them case by case. Indeed, I get lots of missing gem warnings now when I try to type "rails server". Let's address them as follows:
gem install railties
gem install bundler
bundle install
This cleans up the mess and gets me back to the Fixnum/Bignum issue.

Migrate to Rails 5

According to the rails website, rails 5.1.4 is the latest (but there are rumors that rails 5.1.5 is out). I edit several lines in my Gemfile, trimming version numbers off the end of a number of required gems, and commenting out the requirement of the psych gem (that was a workaround for an old Fedora issue). The final crucial things was will_paginate, once I unlocked its version (it was 3.0.4, now it gets 3.1.6 when I do a bundle update) I can start the server.
gem 'rails', '5.1.4'
And on to testing. I point my browser at localhost:3000 and to my surprise, the application starts without errors! Now to try various things. A search fails with the following line triggering an error:
@mountcount = Mount.count( :conditions => [ 'species LIKE ?', target ] )

SQLite3::SQLException: unrecognized token: "{": SELECT COUNT({:conditions=>["location LIKE ?", "%79%"]}) FROM "mounts"
The story here seems to be that a number of drastic API changes have been made to ActiveRecord. It looks like what you do is to do a "where" or some such to specify the records you want and slap the count method on the end of that to just get a count. Bundle update tells me I am now using activerecord 5.1.4

I ended up fixing this with the following. It fetches all the records and counts them, but it works. I never could get the count method to work for me.

# @mountcount = Mount.count( :conditions => [ 'species LIKE ?', target ] )
@mounts = Mount.where( 'species LIKE ?', "#{target}" )
@mountcount = @mounts.length
After this, things seem to be working. I spent a lot of time trying to figure out the new ActiveRecord API. The documentation is pretty shabby. The biggest trouble is that with the API forever changing, whatever books you have on the shelf or examples you find online are generally worthless. One has to wonder if this business of endlessly changing things is job security for the rail cognoscenti. As soon as a new crop of people get decent rails skills, they change things to keep themselves on top. This has been around long enough it should be stable. Enough is enough, look elsewhere.
Feedback? Questions? Drop me a line!

Ruby on Rails notes / tom@mmto.org