...rules for Rails Beautiful controllers Relearning ActiveRecord User interactions without a database Creating a system for growth Dealing with fat models A home for interaction-specific code Extracting service objects...
...As naming convention when extending models with ActiveType::Record[User]. Instead just pick whatever substantive best describes the extended class. Note that we prefer the verbose notation of parent namespaces...
If you have a single node elasticsearch instance and indices with replicas enabled your cluster state will be yellow. If you have replica shards they should be moved to a...
...different node for high availability purposes. With a single node this can't be accomplished. So you either build a ES cluster or you disable the replicas. Building a cluster...
When you send automated emails from a noreply@-address, and the recipient has an out of office enabled, the autoreply bounces and they get an additional email with an error...
...To prevent the recipient's auto-response and the following error message you can set the email header Auto-Submitted: auto-generated in your mailer, for example like this:
Cucumber up to version 2 had a neat feature called Step Argument Transforms which was dropped in favor of Cucumber 3 ParameterTypes. While I strongly encourage you to drop your...
...keep the exact same functionality of your old Transforms while writing them in the style of new ParameterTypes. Why would I want to keep my Transforms? Transforms allowed you to...
Our preferred way of testing ActiveRecord is to simply create/update/destroy the record and then check if the expected behavior has happened. We used to bend over backwards to avoid touching...
...the database for this. For this we used a lot of stubbing and tricks like it_should_run_callbacks. Today we would rather make a few database queries than have...
If validations failed for a record, and you want to find out if a specific validation failed, you can leverage ActiveModel's error objects. You rarely need this in application...
...name (e.g. :blank for :presence, :taken for :uniqueness). You may also use where to see all errors of an attribute: >> user.errors.where(:email) => [#<ActiveModel::Error attribute=email, type=blank, options={}>]
...agent manually. Example: # exec resource: exec { "update_rubygems_${user}_${version}": command => "${home}/.rbenv/shims/gem update --system ${version}", unless => "${home}/.rbenv/shims/gem -v | /bin/grep ${version}", } This does execute rbenv commands. If puppet runs...
...the cogwheel icon (or press F1 when focusing the dev tools) to open the settings overlay. Under "Preferences", in the "Appearance" section, find the "Panel layout" option. Set it to...
Alternatively, press Ctrl+Shift+P and search for "panel layout". Wat? Vertical means that the DOM tree is next to the styles/etc panel, like so:
To query for identical arrays independent of their order you have to either: Sort both the query and database content. If you're on Rails 7.1 you can use...
...the new normalizes macro for this. This solution would still use any indexes on the column. Check for inclusion in both directions, as implemented by the where_array_matches method...
...is defined incorrectly. Raise the attributes hash given to your :reject_if lambda to see if it looks like you expect. If you are nesting forms into nested forms, each...
...a new parent record together with a new child record and will need to save the parent before you can save the child. You can opt to only show the...
...to lock a user in devise. Using the lockable module Customizing the user account status validation when logging in. It depends on your requirements which methods works best.
...user on soft delete We recommend to use option 2 when you want to couple the lock to the model's soft delete logic. Option 1 might also work when...
...of passwords for the root user and you prefer using a password for root. Solution Step 1 is getting a root mysql shell that allows us to change user credentials...
...and MySQL since they share names of binaries. sudo systemctl stop mysql sudo mysqld_safe --skip-grant-tables & This starts the mysql daemon in the background and we can now...
...you have too many inotify instances you may run into limits of your operating system. To find out which process is using them all up you can run:
...For ages, CSS transforms had to be defined using the transform property. For a single transformation, this was something like transform: scale(1.5), and multiple transformations could be applied by...
.example { transform: scale(1.5) rotate(45deg) translateY(-50%); } All modern browsers (Chrome & Edge 104+, Firefox 72+, Safari 14.1+, Samsung Internet 20+) also support individual properties for transforms.
In interactive commands, Git allows the user to provide one-letter input with a single key without hitting enter (docs). # Enabled this feature globally git config --global interactive.singlekey true
...enable this feature locally for a single repository git config interactive.singlekey true This allows you to hit "y" instead of "y + ENTER" to move to the next hunk.
Or: How to avoid and refactor spaghetti code Please note that I tried to keep the examples small. The effects of the methods in this card are of course much...
...more significant with real / more complex code. What are the benefits of more modular code? Code is written once but read often (by your future self and other developers who...
ImageMagick can convert SVGs to raster image formats. Example for PNG: convert input.svg output.png If the SVG has a size of 24x24 (viewBox="0 0 24 24"), the resulting...
...PNG will also have a size of 24x24. Resizing An SVG's viewBox specifies the intended size, but vector image formats can be scaled freely. Resize flag (poor results)
When doing some meta-programming magic and you want to do something for all attributes of a class, you may need to access connection or some of its methods (e.g...
...will encounter fun errors such as: PG::ConnectionBad (for missing databases on PostgreSQL) ActiveRecord::StatementInvalid: PG::UndefinedTable (when database exists, but has no tables) Generally speaking, evaluating model columns during...
Compiling Sass is probably the slowest part of your build, so this is worth a try if you're using Sass...
...If you're using the sass npm package to compile your SASS/SCSS, consider switching to sass-embedded. It should be a drop-in replacement in a large app and it...
...come across objects created by some gem or framework. You don't have the source code at hand, still need to inspect this object. Here are some tools to do...
...from Object. This makes the methods list drastically more relevant. You can also try subtracting other base classes like ActiveRecord::Base.methods etc. To further narrow it down you can also...
Sometimes you have a file that is related to a project, while not actually being part of it. You'd like to keep them around, but others won't need...
...them – e.g. some notes, a log, or a database dump. Sure, you have a project directory – but all of it is tracked by Git. A project's tmp/ directory is...
...group using Ruby's def keyword or define_method method: describe "example" do def sum(a, b) a + b end it "has access to methods defined in its group" do...
...expect(sum(3, 4)).to be(7) end end The helper method is also available to groups nested within that group. The helper method is not available to parent or...
PostgreSQL uses the C library's locale facilities for sorting strings: First, all the letters are compared, ignoring spaces and punctuation. It sorts upper and lower case letters together. So...
...the order will be something like a A b B c C Then, spaces and punctuation are compared to break ties. Example: Ruby PostgreSQL IMAGE3.jpg image2.jpg image.jpg image3.jpg image2.jpg
...tell npm to install a package globally with npm -g install @puppeteer/browsers. However, it seems that its not possible that npx can run commands from global packages without referencing the...
...image, where a testing chrome and chromedriver is installed with a global npm package. Since there is no local project it was more useful to install the package in a...