Monthly Archives: September 2014

rake rails:update:bin

A reminder for when the rails app won’t start with the following error:

/usr/bin/ruby-mri: No such file or directory — script/rails (LoadError)

and there’s nothing in the bin directory. It’s an easy if not obvious fix. How very rails.


Rake definitely broken, giving up with custom tasks

In the same way that the db:seeds rake task is all but unusable (mostly because it will never report a data format error), custom rake tasks using ActiveRecord should be banned.

Two days I have spent try to preload my application for an application to do some integration testing with only ‘ArgumentError: undefined class/module’ errors to show.

In my frustration, I decided to write a small ruby script to read in the exact same YAML file and create the database records. The main reason for writing this script was to see if I could get a hint of any errors in my model or YAML file.

And indeed, that’s what I started to find: a typo in a migration, missed columns, unencoded characters. Piece by piece I was able to take the error reports and fix things to the point where the script and YAML file could create all the data I needed. Taking this YAML file to the rake task. Nothing. Still the same error. Rake and ActiveRecord really aren’t a winning combination. one hours scripting trumps 2 days rake-induced hair-pulling. No more.

And the rake misery continues

Possibly a consequence of going to lunch straight after thinking you’ve fixed something, but I’m now getting errors like,

$ rake -T
rake aborted!
ActiveRecord::AdapterNotSpecified: 'test' database is not configured. Available: []

Now this really is stupid. Sometimes I get an error about the development database not being configured. I am only tryng to do this because of the difficulty getting Rails on my Linux laptop talking to a SQL Server Express database using tiny_tds to do a conversion of the database from MySQL to SQL Server (or the other way round).

I think it’s just baiting me. My one main gripe with Rails has always been that although it’s more efficient in code terms, you have to spend an awful lot of time chasing errors and bugs in the framework which makes the overall development time the same as when doing it all by hand

Although people like Martin Fowler sing the praises of rake, it is blooming hard work and solving problems using the error mesages is like an Araucaria crossword.

More YAML and rake nonsense

My attempts at building custom rake tasks to pre-load initial data for applications continues, and is another widely reported problem.

I have two models, User and Role both in my app/models directory as you’d expect. I do all standard stuff to set up the environment in rake, there are no structural differences at all in the code.

The rake task use users works fine but for roles I get,

rake aborted!
ArgumentError: undefined class/module Role
../lib/taksks/post_migrate_roles.rake:6:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:task_prep_roles
(See full trace by running task with --trace)

Indicating a potential problem with the YAML file; the only difference being the user yml has,

- !ruby/object:User
   id: 1

and the roles.yml has

- !ruby/object:Role
   id: 1

There might be something problems with serialised object at but it’s quite deep and I’m including it here as a reminder to check out later.

What the hell

One minute my Rails app is working and the next I get the error when trying to rak db:migrate the database from scratch:

JSON::ParserError: Caught Encoding::CompatibilityError at ‘[{“content-type”:”ap’: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)

And the accompanying stack trace doesn’t mention any of my files. How the hell am I supposed to troubleshoot this rubbish. I have to spend hours trying to figure out what on earth might be wrong.

Fortunately, I have some version control in place but I’m going to have trash my local copy. pull from git and attempt to recreate all teh work I’ve lost over the past few days.

However, in glorious Rails style and comparing the bundled gems against another working application, it turns out that downgrading to 4.1.0 (from4.1.6) fixes the problem. Still anotehr two hours lost for a non-coding fault that I could not have prevented.