Learn to treat files as an ActiveRecord attribute type, like :string or :integer Research Look at the README for...
...instead of using a more costing feature spec. This is especially useful because they become quite convenient when used with Capybara::Node::Finders and Capybara::RSpecMatchers. This allows to wirte...
...view might be too isolated, since view-specs will mock a lot of rails behavior and render the view independent from the controller-logic. Therefore it will be more applicable...
This still relies on params[:id] existing, so your code should reflect that: # Better User.find(params.expect(:id)) # Or User.find(params.require(:id)) Avoiding issues with extra parameters Rails logs extra...
...should still use permit (or expect) to receive Strong Parameters, but strip extra parameters. # Better (option 1) redirect_to users_path(params.slice(:query, :encoding).permit(:query, :encoding)) # Better (option...
ActiveSupport (since 4.1) includes test helpers to manipulate time, just like the Timecop gem: To freeze the current time, use...
If you're responsible for gatekeeping in a projects, here is a guide, what to do. In order to reduce...
...a feature look and feel). Frequent deploy gets changes to users faster. We sleep better, because we know stuff still works. Make sure no one removes a feature by accident...
...application changes. The more tests you already have, the less useful an additional test becomes ("Diminishing returns"). Tests sometimes fail even though the code is fine, especially when the test...
Ever needed to migrate data between Redis instances? Give RIOT - Redis Input/Output Tools a try. It supports migration to different...
...requestAnimationFrame can be used to reduce the number of repaints for animations. This might benefit your application performance. Read Don't throw exceptions from async functions What Color Is Your...
...helperFunction? What happens when you remove the await of init? What causes the new behavior? Now have a look at this sketched usage of asynchronous functions: const news = await fetchNews...
When selecting records in a date range, take care not to do it like this: start_date = Date.parse('2007-05...
It might sometimes be useful to check whether your Rails application accesses the file system unnecessarily, for example if your...
You can convert git commits into patch files. Those can be used to apply to a different repository [1] or...
Download buttons can be difficult to test, especially with Selenium. Depending on browser, user settings and response headers, one of...
Resources Rails Guide: Internationalization API Guide to localizing a Rails application Locale-aware helpers in ActionView::Helpers::NumberHelper
...never influence each other On a similar note, we don't want tests to behave differently based on their execution order or parallelism. One core mechanism in this regard is...
...give your Movie model a #person attribute. Instead, use FactoryBot's transient attributes and before/after hooks to implement the factory above...
To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with...
...rendering quality is now fine in recent versions of wkhtmltopdf (0.12+). You will never beat LaTeX if you need perfect font rendering. If you are observing strange behavior when including...
...might experience that your application "locks up" whenever you request a .pdf route. This behavior is caused by a deadlock: The Rails process is trying to render the page to...
For webpages to load fast it's recommended to optimize images. Ideally an image's file size should be as...
Developing or debugging SAML functionality can be a hassle, especially when you need to go back and forth with someone...
Due to the way we setup Jasmine tests in our projects, you may run into various errors when Jasmine boots...
...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 long texts...
...starts wrapping within its container. This is most probably because there is no defined behavior in case multiple text contents are rendered next to each other (horizontally) and the clamping...
def self.acquire(name) already_acquired = definitely_acquired?(name) if already_acquired yield else begin create(:name => name) unless find_by_name(name) rescue ActiveRecord::StatementInvalid # concurrent create is okay...
begin result = nil transaction do find_by_name(name, :lock => true) # this is the call that will block acquired_lock(name) result = yield end result ensure maybe_released_lock...
You cannot use Array#join on an array of strings where some strings are html_safe and others are not...
Full-text search can reach its limits in terms of flexibility and performance. In such cases, trigram indexes (pg_trgm...
In Rails 8 the behavior of the rails db:migrate command has changed for fresh databases (see PR #52830). Before Rails 8: The command runs all migrations in the folder...