Error installing json 1.8.3 with ruby 2.4


You are trying to install the gems for your rails application in a new computer, or by using ruby 2.4 and you get the following error:


Remove your old Gemfile.lock file and run bundle again. A newer version of json (ie 1.8.6) should be installed.

ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: …


You have a Ruby on Rails application/engine with some tests in Minitest and using postgresql as the db. In the original development environment all the tests that use fixtures and foreign key validations pass, but when you try to move to a different environment with new database some or all of you tests fail with a message that refers to the ForeignKeyViolation as in:


Since active record disables the foreign keys before loading the fixtures in the database, the user that you run the tests with needs to have superuser permissions in the test database. Otherwise the fixtures are not loaded. So add the superuser permissions to your user:

You may need to drop and create your test database.

Running a specific Cop in Rubocop


You are working on an existing rails project with many rubocop warnings and you would like to fix certain types or warnings by getting only the specified files.


So for example when you use rubocop you first get the following for all the files in the project:

You can get a grouping of the errors by using the following:

If you would like to know only the files for a certain type of warning to be able to fix them you could try the following:

Using Array.wrap in Rails when the results could either be a string or an array


You want to use some array method in a value returned, which can either be a single value or an array of values.


Rails ActiveSupport Array, provides a method called wrap, that can be used to:

Wraps its argument in an array unless it is already an array (or array-like)

Full explanation of the method here.

Thanks Miles

SSL received a record that exceeded the maximum permissible length.


You want to install rbenv, but when you are trying to clone the code with:

you get the following error:


If you are behind a proxy server make sure that you add your proxy server details in your ~/.bash_profile and source the file afterwards.

So first add the details of your proxy like:

And finally source the file before running the installation again:

Creating a simple rails docker image for testing in cloud deployment

Trying to deploy a rails application in a cloud provider ie dreamhost, that uses OpenStack these are the steps needed:

  1. Install docker in your development machine and your cloud provider by following the installation instructions from here
  2. Create an account in Docker Hub, that will be needed later on to push your docker image with the application
  3. Pull the official rails docker image to your development environment:
  4. Create a new simple rails application:
  5. Change to the application directory and add a Dockerfile in the root directory containing the following:
  6. Build your new image by using:
  7. Check that your image was build by using:
  8. Start the container with:
  9. Make sure that you can see the initial rails page by using your browser to go to
  10. Push your image to your Docker Hub account by first logging in to it from the command line: , and then when you get ‘Login Succeeded’, push your image to your account:
  11. TBC

Could not find libv8- in any of the sources


You are trying to upgrade one of your gems (ie uglifier) and at the same time you are using a new gemset (ie for rails 4.2.4), and you get the following error when you are trying to bundle:


Upgrade to rails 4.2.4 first and bundle and afterwards change the other gem and do bundle again.

make the unpermitted parameters errors in Ruby on Rails more obvious


When you are adding new attributes to your model after the initial creation, they are not by default included in the permitted parameters list. Sometimes the error is not so obvious to see when testing, unless you look at the test log files.


To make the error more obvious, there is the following configuration option that you can set up in config/environments/test.rb (tip taken from Rails 4 In Action):

minitest assert_routing with method included in path


When trying to use the minitest assert_routing with the first parameter representing the path as a hash that includes both the path and the method, and run the tests rails complains about SyntaxErrors.

When trying to use it as suggested in the ‘Rails 4 Test Prescriptions’ Pragmatic Programmers book (p. 172 – Minitest and Routing) which is:

the error is:

even when trying to have the second parameter as a hash:

the error is similar:


Seems that you need to pass the parameters enclosed in brackets, so the following would work:

bin/rails:6: warning: already initialized constant APP_PATH


You are getting the error:

when you are trying to start the local webserver with rails s.


That happens when are using the bootstrap rails gem as in:

It is important that the bootstap rails uses in the require is used with a dash and NOT an underscore.
So when you write the the gem as follows:

and restart your server you should no longer have the error message.