I got this error after upgrading Ruby from 2.4.5 to 2.6.4 when I opened the Rails console -
rails server still worked.
Running via Spring preloader in process 14679
Loading development environment (Rails 22.214.171.124)
Traceback (most recent call last): …/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:175:in 'fork': No such file to load – irb/encoding_aliases.rb (LoadError) …/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:175:in 'fork': undefined method 'reject!' for nil:NilClass (NoMethodError) …/li…
Updating Chromedriver is often a hassle: If you use
chromium-chromedriver from the Ubuntu sources, it usually won't be updated when a new Chrome version is released. Manually downloading it from the official page is a very manual process. And I don't really want to use remote code like the "webdrives" gem because of paranoia.
Cry no more, for here is a tiny bash script that will download the latest chromedriver version and place it inside
~/bin. (If you use a different location, adjust accordingly).
If you're suffering from a huge
de.yml or similiar file, cry no more. Rails lets you freely organize your dictionary files in
My organization works like this:
With this gem your
transaction blocks raise an error when they have side effects that cannot be rolled back.
By default it checks whether you're connecting with HTTP, queuing a Sidekiq job or sending an e-mail within a
transaction. You can add custom checks, too.
Found in this RubyGuides article.
The ruby sass gem also installs a command line tool to convert to and from SCSS. Use it for a directory of
sass-convert -R assets/stylesheets --from scss --to sass
We use bundler to maintain a projects gems. Unfortunately bundler v1 itself is incompatible with bundler v2.
You have two ways to update bundler on the server.
If you use our gem capistrano-opscomplete in your project, you can tell opscomplete to install the required bundler version:
Add the following line to
deploy.rb. If you use different deployment targets, add the follwoing line to the specific target configuration file. (e.g `product…
When using threads, you must make your code thread-safe. This can be done by either locking (mutexes) all data shared between threads, or by only using immutable data structures. Ruby core classes like
Array are not immutable.
There's several gems providing thread-safe collection classes in Ruby.
The concurrent-ruby gem provides thread-safe versions of
sa = Concurrent::Array.new # supports standard Array.new forms
sh = Conc…
When upgrading Clearance, pay attention whether the password hashing strategy might have changed. Old clearance versions (< 1.0) used SHA1-encrypted passwords by default. Current versions default to BCrypt.
If you simply upgrade without taking this into account, users will get a
BCrypt::Errors::InvalidHash when trying to sign in. Your tests will not notice this, since they create new users for each scenario.
To fix it, you'll either have to force all users to reset their passwords, or you can allow old users to keep signing in with t…
On application servers, gems are usually bundled into the project directory, at a location shared across deployments.
This is usually
shared/bundle inside your project's root directory, e.g.
If you can't find that, take a look at
current/.bundle/config and look for
When you are changing the version of RubyGems or Bundler on a system where gems are installed this way, you must wipe that bundle directory in addition to the user and system gems or gems that are already ins…
Adding a gem means you take over the liability towards the external code.
Based on "To gem, or not to gem":
Rails supports time zones, but there are several pitfalls. Most importantly because
Time.current are completely different things and code from gems might use one or the other.
Especially configuring an application that cares only about one time zone is a bit tricky.
The following was tested on Rails 5.1 but should apply to Rails 4.2 as well.
Your life will be easier if your application does not need to support time zones. Disable them like this:
config.time_zone = 'Berlin' # Your local time…
RubyMine comes with a nice way to grep through your project's files: The finder (
ctrl + shift + f). Don't be discouraged about the notice
100+ matches in n+ files if your searched keyword is too general or widely used in your project.
RubyMine comes with a few ways to narrow down the resulting list, don't hesitate to apply those filters to speed up your search. Your keybinding might vary based on your personal settings.
alt + k)
If you already know the file extension of your …
Webpacker is a wrapper around webpack that handles integration with Rails.
This is a short introduction.
If you haven't already, you need to install node.js and Yarn.
gem 'webpacker', '~> 4.x' # check if 4.x is still cu…
If your Ruby project includes a gem like Spreewald that comes with some external step definition, RubyMine does not know about them by default and will highlight the step as an undefined reference:
To link these external step definitions to RubyMine, add the corresponding gems to your RubyMine-Settings:
ctrl + alt + s)
Reading a URL via GET:
Defining any HTTP method (like POST or PUT):
curl http://example.com/users/1 -XPUT
Sending data with a request:
curl http://example.com/users -d"first_name=Bruce&last_name=Wayne"
If you use
-d and do not set an HTTP request method it automatically defaults to POST.
Performing basic authentication:
All together now:
curl http://user:firstname.lastname@example.org/users/1 -XPUT -d"screen_name=batman"
This is pretty much like defining subclasses through traits with the Modularity gem.
module MyConstantTrait as_trait do self::MY_CONSTANT = 'hello universe' end end
This would set
MY_CONSTANT for any class using the trait.
Of course you can also use parameters (for logic or for setting values, like here):
module DoesValues as_trait do |*args| self::VALUES = args end end class Foo include D...
json fails to install for Ruby 2.5 if you use a version equal or below
bundle update json --conservative to solve this issue.
The backtrace you will encounter looks like this:
Building native extensions. This could take a while…
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /home/user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/json-1.8.3/ext/json/ext/generator /home/user/.rbenv/versions/2.5.3/bin/ruby -I /home/user/.rbenv/versions/2.5.3/lib/ruby/si...