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
Update: This is now documented on Edgeguides Ruby on Rails: If you set the :validate option to true, then associated objects will be validated whenever you save this...
...default, this is false: associated objects will not be validated when this object is saved. Setup # post.rb class Post < ActiveRecord::Base has_one :attachment end # attachment.rb class Attachment < ActiveRecord::Base...
...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...
Ever wondered how you can create a simple table output in bash? You can use the tool column for creating a simple table output. Column gives you the possibility to...
...same level. Pipe output to column -t (maybe configure the delimeter with -s) and see the magic happening. detailed example I needed to separate a list of databases and their...
...really want to get their arguments processable as keyword arguments. Don't change the syntax, or you'll experience pain. Always call super inside of your overridden #initialize method. A...
...things happen in the ActiveRecord world. Just let them happen, otherwise kittens will die somewhere. You don't want that. Example class Item < ActiveType::Object def initialize(attributes) super
For searching in large database tables we usually use PostgreSQL's fulltext search capabilities. While this works reasonably well for content primarily consisting of prose, it is not necessarily a...
...good solution for all use cases. The main issue is that it is only possible to search for prefixes of text tokens, which can potentially be unexpected for users.
...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...
...browser's HTTPS handling works as expected (which might be compromised e.g. due to security products or enterprise proxy servers...
...Chrome to check if the problem disappears. Keep in mind though that running outdated software, especially web browsers, is in most cases not a good idea. Please verify periodically if...
...you still need to run the old version or if an even more recently updated version fixes the problems introduced in your version. Here's how to get old versions...
...window manager that provides neat features like automatic layouting of windows, good multi-display support with per display workspaces and more. Since it is only a window manager, you will...
...menus, automatic updates etc. Fortunately, you can run Awesome within MATE, by following these steps (tested on Ubuntu MATE 16.04): Awesome + MATE Create the following file at /usr/share/xsessions/Xsession.desktop: [Desktop Entry...
Detecting if a Javascript is running under Selenium WebDriver is super-painful. It's much easier to detect the current Rails environment instead. You might be better of checking against...
...the name of the current Rails environment. To do this, store the environment name in a data-environment of your . E.g., in your application layout: <html data-environment=<%= Rails.env %>>
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...
I recently had to update a few selective npm libraries in a project that uses pnpm to apply a CVE mitigation. My first instinct was to modify the package.json file...
...a much better way. Use pnpm up (aliased to update and upgrade) with a set of exact library names and versions. The resulting changes (both to the package.json and pnpm...
To set a cookie in your test browser for cucumber tests, you need to know which driver you are using. Use the step below according to your driver.
...to "([^\"]+)"$/ do |key, value| headers = {} Rack::Utils.set_cookie_header!(headers, key, value) cookie_string = headers['Set-Cookie'] Capybara.current_session.driver.browser.set_cookie(cookie_string) end Note that Rack::Utils is only used to...
Select2 is a fantastic library for advanced dropdown boxes, but it depends on jQuery. Alternatives Tom Select There is a selectize.js fork called Tom Select. It is well tested, comes...
...with Bootstrap 3, Bootstrap 4 and Bootstrap 5 styles and is easy to use. You might miss some advanced features. Known issues: Dynamic opt-groups in AJAX requests are not...
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:
...ae]y => grey or gray => but NOT graay or graey [0-9] matches a SINGLE digit in the range from 0 to 9 [0-9a-fA-F] hexadecimal digit...
...with caution. Mostly you'll want to use it for small expressions, e.g. for nested sub-regexes. For more details have a look at the card on quantifier modes.
Starting Terminator with split screens is quite simple: Just store a layout and start Terminator with the --layout option. However, if you want to run custom commands in your terminals...
...command exits. You accomplish this by tweaking bash to run a command before actually starting. Pimp your .bashrc Add this to the end of .bashrc: # hack to keep a bash...
to create a Gallery that has a name and has_many :images, which in turn have a caption to offer the user a single form to create...
...with any number of images immediate uploads with a progress bar per image a snappy UI Enter jQuery File Upload. It's a mature library that can do the job...
Git log offers useful options for filtering. This card provides a short overview. By message Only commits that include a specific string in their commit message git log --grep="tracker...
By file Only commits that introduced changes to a specific file git log -- foo.rb bar.rb Note In case the file was renamed or moved the --follow option can be...
When you need to see the content of a page (i.e. not all the HTML but the relevant text body) you can do pp (html_content) pp will format the...
...html String human readable pretty printed where html_content can be replaced by one of the following commands: Rails body or response.body Capybara: page.driver.html.content page.body Webrat: Nokogiri::HTML(response.body).content...
Somewhat regularly, you will need to filter a list down to some items and then map them to another value. You can of course chain map and compact, or select/filter...
...if i.even? }.compact => [4, 8, 12] or >> [1, 2, 3, 4, 5, 6].select(&:even?).map { |i| i * 2 } => [4, 8, 12] you can just do...
When you have string contents (e.g. a generated binary stream, or data from a remote source) that you want to store as a file using Carrierwave, here is a simple...
While you could write your string to a file and pass that file to Carrierwave, why even bother? You already have your string (or stream). However, a plain StringIO...
Rails comes with a Rake task notes that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE". While it's generally not good practice to leave them in your...
...not yet available. To keep track of them, run rake notes. Its output looks something like this: $ rake notes app/controllers/frontend/media_documents_controller.rb: * [ 6] [TODO] should be part of a publication workflow app/helpers/frontend/slider_helper.rb...