When you use Sentry to monitor exceptions, an important feature is Sentry's error grouping mechanism. It will aggregate similar...
...t raise an error. Instead, rescue the exception type that you are expecting: @user = begin User.power_find(something) rescue ActiveRecord::RecordNotFound User.new end This also applies to the quite popular...
...nil" and "full" rescue blocks that don't explicitly rescue away an error class: begin # do stuff rescue # rescues any StandardError end Note that there may be cases where you...
...change the rendered html, some variation of @message.content.body.to_rendered_html_with_layout Changing the behavior of the editor You may want to add some functionality to the editor or remove...
...addEventListener("trix-action-invoke", event => { const { editor } = event.target if (event.actionName === "x-horizontal-rule") { // ... } // Add behavior for the other buttons // ... }) Check the Trix README to check what you can do.
...John Doe <user@example.com> Date: Thu Dec 23 13:37:00 2010 +0100 make everything better Once you are done bisecting you can go back with git bisect reset
...t have control of. Solutions Don't log SQL queries. This is the default behavior of rails but can be changed in the config/environment/production.rb file: config.log_level should not be...
...would allow to detect the end of windows size changing process. Capybara provides a better way to manipulate the browser window which you should use instead: page.current_window.resize_to. Good: Capybara...
...as isolated (more unit like) tests, one might want to test some cookie dependent behavior as a request, helper or model spec too. Since the rspec documentation on testing cookies...
...that into a class to DRY up your code and write solid unit tests. Beware that your class will not be able to read the cookies, since they are only...
When ending a Selenium test Capybara resets the browser state by closing the tab, clearing cookies, localStorage, etc.
This card will show you how to use git rebase --onto without confusion. Use case: You've got two feature...
...changes you make to the database will be rolled back on exit. Warning Changes beyond the database (deleting files, sending emails, etc) cannot be rolled back...
class Post < ActiveRecord::Base has_one :attachment end # attachment.rb class Attachment < ActiveRecord::Base belongs_to :post validates :title, presence: true end Issue When creating a post with an invalid...
vertical-align is hard. Have you ever wanted to vertically center an icon with text? This usually means "vertically align...
In a web application you sometimes have tasks that can not be processed during a request but need to go...
...shared_examples_for can have parameters. You can simply hand over arguments from it_behaves_like: shared_examples_for 'string equaling another string' do |expected_string| it 'is equal to...
...subject).to eq(expected_string) end end describe 'some string' do subject { 'foo' } it_behaves_like 'string equaling another string', 'foo' end RSpec 1 Use it_should_act_like from...
I encountered a unlucky behavior of byebug 11.1.3 (the most recent version at time of writing) when using it with Rails 6 and it's new autoloading component, zeitwerk. There...
To apply transparency to an element, you can use opacity in CSS. However, sometimes you don't want to make...
...to e.g. lock an entire form while it is being changed. This requires code beyond database locking, in both backend and frontend...
...index: true option. Use it only inside create_table or for add_reference (= add_belongs_to) statements, and use add_index for other cases. Never use index: true but only...
For Rails models where only one of multiple attributes may be filled out at the same time, there is no...
This is painful. Consider using Microsoft Office or switching careers. If you need to write < 20 letters consider doing it...
Building application assets with esbuild is the new way to do it, and it's great, especially in combination with...
I recently enjoyed debugging a Cucumber step that tried to be retryable using a patiently block: Then /^"([^"]*)" should( not)? be...
Rails' url_for is useful for generating routes from a Hash, but can lead to an open redirect vulnerability.
TL;DR There are three dimensions you can control when scoping routes: path helpers, URL segments, and controller/view module.