When two classes implement the same behavior (methods, callbacks, etc.), you should extract that behavior into a trait or module. This card describes how to test that extracted behavior without...
...repeating yourself. Note that the examples below use Modularity traits to extract shared behavior. This is simply because we like to do it that way at makandra. The same techniques...
Since I use this a lot in my daily work and there were no scripts working properly for me, I...
...all Unpoly updates work using AJAX requests, you won't get the more detailled better_errors page with the interactive REPL. Below is an event listener that automatically repeats the...
...full CSS and JavaScript. The code assumes you are using Ruby on Rails with better_errors, which is the default error view that modern Rails versions employ. If you are...
IRB 1.2 (shipped with Ruby 2.7, but works on 2.5+) brings pretty syntax highlighting and multiline cursor navigation. However, pasting...
Capybara provides execute_script and evaluate_script to execute JavaScript code in a Selenium-controlled browser. This however is not...
TL;DR PostgreSQL handles Rails 4+ text and string columns the same. Some libraries may still reflect on the column...
The parallel-gem is quite easy to use and can speed up rendering time if you want to render the...
...between added? and of_kind? While added? might feel more natural to use, it behaves differently than of_kind? because it also compares options from the validation error. of_kind...
When HTTP clients make an request they can define which response formats they can process. They do it by adding...
While it might be tempting to set it per project (other devs might benefit from it), you need to do it each time for every project "pollute" a project...
This card explains how to generate an entity relationship diagram for your Rails application. We also show how to limit...
There is no one-liner in Ruby or ActiveSupport with the behavior described above. There have been discussions about adding a method like Enumerable#find_map:
...Middleman brings Haml, Sass, helpers etc. However, it can be configured to do even better. This card is a list of improvement hints for a Rails developer. Gemfile
...helpers in a helpers {...
...} block. However, this does not scale very well. You're best off creating a /helpers directory and putting helper files there just like you know it...
The robots.txt file and HTML tag can be used to control the behavior of search engine crawlers. Both have different effects. robots.txt Marking a URL path as "disallowed" in robots.txt...
The Node Version Manager allows installing multiple NodeJS versions and switching between them. By default, it does not automatically switch...
...not scale the icon with the font size. One option that seems to work better is to use the mask CSS feature. The idea is to have an element with...
...var(--icon-url) center / contain no-repeat // this can probably be done in a better way: vertical-align: text-bottom margin-bottom: -.1em // depends on the icons @each $icon in...
Besides Plotting graphs in Ruby with Gruff, which comes handy for many uses cases, you sometimes might need configuration for more advanced plots, e.g. for academic concerns. Then using Gnuplot...
...where each array holds the data for x-, y- or z-axis. The major benefit of numo-gnuplot is that it supports advanced numpy like array operations, like multi array...
If you ever need to restore exact records from one database to another, Marshal might come in handy. Marshal.dump is...
SimpleForm is a great approach to simplifying your forms, and it comes with lots of well-defined input types. However...
...find(..., visible: true) or find(..., visible: :visible). Note that you could change the default behavior by setting the ignore_hidden_elements config option. However, ignoring invisible elements is a useful...
We're always striving towards keeping our website's JavaScript as small as possible. If you're using webpack(er...
While both the alt attribute and the figcaption element provide a way to describe images, the way we write for...
A lesser known fact about PG enums is that they are ordered. This can be really handy when values have...
...Rails has a method ActiveRecord::Relation#merge that can merge ActiveRecord scopes. However, its behavior has never been clear, and in Rails 7 it still discards conditions on the same...
...column by the last condition. We discourage using #merge!) The best way to merge ActiveRecord scopes is using a subquery: scope_a.where(id: scope_b) It is a little less concise...