Thursday, 5 December 2019

Golang and private gitlab repos and 410 Gone

I've been following a microservices with golang tutorial recently, and needed to refer to one project from another.

After getting numerous errors with `go get` and much searching for answers, I stumbled across this solution.

In Gitlab add a personal access token.

In your ~/.netrc file add:

machine gitlab.com
  login {{personal_access_token_name}}
  password {{personal_access_token}}


Replacing the prompts with the actual values.

In your .bashrc add

export GOPRIVATE="gitlab.com/{{path_to_project}}"


This is working for me, a similar approach may well work with bitbucket or codebasehq.

Sunday, 3 March 2019

OSX and image not found readline.bundle

Something changed recently in my osx configuration, I'm not sure what, but it broke readline on the macbook.

The key part of the error message  was:

Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
  Referenced from: /Users/stokern/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
  Reason: image not found - /Users/stokern/.rbenv/versions/2.5.3/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle


The fix was to add the ruby readline gem:

group :development, :test do
  ...
  gem 'rb-readline'
end

This is the second time this has caught me out, so I thought I'd document it.

You're welcome

Saturday, 17 November 2018

OS X Unable to build mysql2 gem


The problem:
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
The solution:
gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"

Note that these are mainly notes to myself, but if you find them helpful then you're welcome.

Monday, 22 October 2018

rails-sass is deprecated

I've been seeing this for a while, and have finally got round to finding a solution.

In the project `Gemfile`, remove the reference to `sass-rails` and replace with `sassc`.

Sigh. It took more than two minutes to find the fix, so logging it here

Saturday, 7 July 2018

NameError: uninitialized constant RailsERD

This has been an occasional annoyance when setting up new Rails projects with the rails-erd gem.

The documentation for the gem is to add

gem 'rails-erd', :require=>false

into the Gemfile, and then run rails g erd:install to add the hook to run when a rails db:migrate is carried out.

I found that this creates /lib/tasks/auto_generate_diagram.rake containing

if Rails.env.development?
  RailsERD.load_tasks
end


One solution is to remove the :require=>false from the Gemfile, but apparently this may have an impact on efficiency rails erd issue 282.

I tried a slightly different approach, and changed /lib/tasks/auto_generate_diagram.rake to require the gem.

if Rails.env.development?
  require 'rails-erd'
  RailsERD.load_tasks
end

Sunday, 21 January 2018

Publishing Rails 5 apps to heroku

When attempting to migrate the database, I was getting errors with the following two messages

Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0. Make sure all dependencies are added to Gemfile.


The second one turned out to be the main issue.

A solution was found in a rails issue 31669, briefly

Thank you for the issue. Rails still don't support pg 1.0.

My solution was to change the Gemfile reference to

group :production do
gem 'pg', '~> 0.18'
gem 'rails_12factor'
end

And the migration succeeded. Now to apply the issue to the other app I was looking at yesterday...

Rails 5 and optional has_many relationships

This is a continuation in the random notes from attempting to learn Ruby on Rails.

Todays' rambling is to do with having an optional relationship between two tables.
erd from project


I am building an application to help me track fuel usage, and was wanting to have a relationship set between Users and Vehicles, based on the diagram.

The spec tests were failing, because the User:Vehicle relationship was mandatory.

The issue appears to be that Rails 5 has made the belongs_to relationship required (as found in the answer to a StackOverflow question).

The solution seems relatively simple, add the optional link to the relationship:
 
belongs_to :user, optional: true
 
My tests are all passing again. For now.