Note: You won't need this for single lines of text. In this case it is better to just use the text-overflow property: Use CSS "text-overflow" to truncate...
...use -webkit-line-clamp in your CSS/SASS to natively render an ellipsis (...) after a specific amount of lines for a multi-line text in your HTML. Earlier, it was necessary...
Sometimes the need arises for SSL in local development. We have guides for different webservers, this one is for puma. make sure mkcert is installed create an SSL certificate for...
...bundle exec rails s Accept the certificate in your browser See also Creating a self-signed certificate for local HTTPS development
Plot graphs in Ruby WebGraphviz renders in your browser via JavaScript (to store the rendered graph, extract the SVG using your browser's DOM inspector) GraphViz with DOT: Online...
...graphviz.christine.website/ or offline https://makandracards.com/makandra/1589-auto-generate-state_machine-graphs-as-png-images Balsamiq Draw.io Excalidraw Asciiflow Google Presentation Egon.io: Domain storytelling with replay functionality (good to visualize and present flows) Gnuplot Ruby Bindings: Especially for more...
tl;dr: Ruby's Bundler environment is passed on to system calls, which may not be what you may want as it changes gem and binary lookup. Use Bundler.with_original...
...env to restore the environment's state before Bundler was launched. Do this whenever you want to execute shell commands inside other bundles. Example outline Consider this setup: my_project/Gemfile...
...at the same time. When assets did not change, we do not want to spend time compiling them. Here is our solution for all that. Its concept should work for...
...all test suites. Copy the following to config/initializers/webpacker_compile_once.rb. It will patch Webpacker, but only for the test environment: # Avoid hardcoded asset hosts in webpack, otherwise all chunks would be loaded...
...git rebase -i main. What it does: Opens an interactive rebase UI to choose squash/edit/fixup for each commit of your branch until the first commit (the base). Keeps your branch...
...s base intact (no rebasing onto main). Lets you squash, reorder, edit, or drop commits. Info This is not the same as git rebase -i main, which would rebase your...
A recent patch level Ruby update caused troubles to some of us as applications started to complain about incompatible gem versions. I'll try to explain how the faulty state...
...care of a few things: The new Ruby version is installed The Bundler version stated in the Gemfile.lock is installed Geordi is installed (for database dumps) The gems of the...
When giving a presentation where you do some coding, the font size you usually use is probably a bit too small and makes code hard to read for users on...
...smaller screens or low-bandwidth connections when the image quality is lower. Here are two solutions. Presentation Mode RubyMine offers a "Presentation Mode" which you can use. Simply navigate to...
When internationalizing your Rails app, you'll be replacing strings like 'Please enter your name' with t('.name_prompt'). You will be adding keys to your config/locales/*.yml files over...
...the right place is a challenging task. The gem i18n-tasks has you covered. See its README for a list of things it will do for you. Note
Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations do the same: class Migration1 < ActiveRecord::Migration[5.2]
...Migration2 < ActiveRecord::Migration[5.2] def up add_column :users, :trashed, :boolean update("UPDATE users SET trashed = #{quoted_false}") end end The plain SQL migration is less code, but has a...
...a new callback to your model that (e.g.) caches some data when it is saved. Now you need to run that callback for the 10000 existing records in the production...
Write a clever migration, possibly by embedding the model into the migration script. Open the Rails console after deployment and re-save every single record. You should probably...
...listen to other events. Quirks The "default behavior" in this case is not to show an alert, and preventing this default means the alert is being shown. In ancient browsers...
...customize the alert text, but this is no longer possible. You might want to set event.returnValue = true, as a truthy returnValue was necessary to trigger the alert in Chrome...
Most browsers have built-in drag and drop support for different page elements like text and images. While this may be useful in most situations, it may become annoying in...
...functionality. This does no longer work. You may now achieve this by explicitly preventing the startdrag-event:
const noDragElement = document.querySelector('no-drag-pls') noDragElement.addEventListener('dragstart', event => event.preventDefault())
Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag these posts with a limited number of tags. The following...
...In most cases you want to use Option 4 with assignable values. The basic setup for all options looks like this: config/routes.rb Rails.application.routes.draw do root "posts#index" resources :posts, except...
...a RubyMine plugin that enables you to review and process merge requests within RubyMine! Setup Open RubyMine settings (Ctrl + Alt + S) > Plugins > Search for "GitLab" > Install (You might need to...
...re-open settings afterwards.) In the RubyMine settings > Version Control > GitLab > Connect your GitLab account with "+" Working with merge requests From the Actions menu (Ctrl + Shift + A), choose "View merge...
When you make a simple TCP connection to a remote server (like telnet), your client won't normally notice when the connection is unexpectly severed on the remote side. E.g...
...if someone would disconnect a network cable from the server you're connected to, no client would notice. It would simply look like nothing is being sent. You can detect...
In Rails, we usually have a mailer setup like this: class MyMailer < ActionMailer::Base def newsletter mail to: 'receiver@host.tld', from: 'sender@host.tld', subject: 'My mail' end end If you want to...
...Rails will print the mail's text representation to your log/development.log. You may also save this output as-is to an .eml file and open it with your mail client...
Bundler allows you to specify the name of the Gemfile you want to bundle with the BUNDLE_GEMFILE environment variable. BUNDLE_GEMFILE=Gemfile.rails.7.2 bundle By default, bundler will look...
...have multiple Gemfiles in your project, which cannot all be named Gemfile. Let's say for example, you maintain a gem and want to run automated tests against multiple rails...
Let's say you have a form that you render a few times but you would like to customize your submit section each time. You can achieve this by rendering...
...form partial as layout and passing in a block. Your template or partial then serves as the surrounding layout of the block that you pass in. You can then yield...
The issue: You are using stub_const to change a constant value for your test. stub_const "SomeClass::CONST", 'test' All of a sudden, tests fail with undefined method 'some...
...method' for # . The reason When using stub_const before the Class containing the constant has been loaded, a module is automatically created with the name. Since RSpec does no autoloading...
When you want to filter records in a model where a string column roughly matches a given term, you can use PostgreSQL’s trigram similarity search. Writing a fuzzy query...
User.where("similarity(name, ?) > 0.3", "John") This finds all users where the name is similar to "John" with a similarity score above 0.3. You can tune the threshold:
Some users might use Adblock Plus or similar browser plugins to reduce the number of ads displayed. If you run into an issue that your application or part of an...
...our web apps. But if your application uses iframes or is embedded in another site it's more prone to it. Blocked elements most of the time appear to the...
...If you are plucking from the id column in particular you can also say: User.active.ids => [1, 5, 23, 42] For a DISTINCT selection, use distinct on your scope (not the...
...resulting array). Article.distinct.pluck(:state) # SELECT DISTINCT state FROM articles => ['draft', 'published'] In Rails 3 and 4 you must use uniq instead of distinct: Article.uniq.pluck(:state) # SELECT DISTINCT state FROM articles...
When testing your command line application with Aruba, you might need to stub out other binaries you don't want to be invoked by your test. Aruba Doubles is a...
Install the gem as instructed by its README, then put this Before block somewhere into features/support: Before do ArubaDoubles::Double.setup prepend_environment_variable 'PATH', ArubaDoubles::Double.bindir + ':' end