...See this ES6 compatibility matrix for details. ES6 and Uglifier If you're using Rails with the assets pipeline (sprockets) you are probably using Uglifier to minify your JavaScript.
...can check if that's an issue for your project by running bundle exec rails assets:precompile in your development environment (don't forget to run bundle exec assets:clobber...
Rails offers several ways to remove records. They differ in whether they instantiate records, fire callbacks (including dependent: associations) and how they manage relation state afterward. destroy_all
...a few minor exceptions for our Austrian friends. Luckily, the I18n gem used by Rails has a fallback feature where you can make one locale file fall back to another...
... and another locale config/locales/de_AT.yml: de_AT: # only a handful exceptions here Now configure Rails to make de_AT fall back to de_DE: Rails.application.configure do config.i18n.fallbacks = { de_AT: :de...
...If you trigger a COUNT query for an association of an an unsaved record, Rails will try to load all children where the foreign key IS NULL. This is not...
Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and code from gems might use one or the other.
...only about one time zone is a bit tricky. The following was tested on Rails 5.1 but should apply to Rails 4.2 as well. Using only local time
...written as a Ruby Gem and was tested and evaluated against one Ruby on Rails project. This card will summarize and present the research results, the evaluation and the programmed...
...The tool should be suitable for modern web based development workflows with Ruby on Rails. Criteria Faster results of failing tests than random prioritization to lower regression testing costs.
...our applications. Hunting it down, we found that the memory leak was located in Rails' #prepend_view_path. It occurs when the instance method prepend_view_path is called in...
...in your ApplicationController, you can just use #prepend_view_path as before. Note that Rails 7 version differs slightly. Known affected Rails versions (maybe more): Rails 4.0 - 7.0
...insert many records is to have a single INSERT statement describing multiple rows. In Rails 6+ you can do so with ActiveRecord::Base.insert_all. This is very fast, but you...
In Rails, the implicit_order_column (added in Rails 6) is a configuration option that helps you define the default sorting behavior of ActiveRecord queries when no explicit ORDER BY...
...clause is provided. This option allows you to specify a column that Rails will use to automatically sort records in a particular order when no specific ordering is given.
Rails includes a way to see what an e-mail will look like. Integration to RSpec All you need to do is implement a preview-class in spec/mailers/previews/notifier_preview.rb: class NotifierPreview...
end end And adapt the preview load path in your application.rb: config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" # For Rails < 7.1 config.action_mailer.preview_paths << "#{Rails.root}/spec/mailers/previews" # For Rails >= 7.1 Then a preview will...
Rails log files rotate automatically when they reach approx. 100MB: $ ls -lh log/ -rw-r--r-- 1 user group 55M Sep 15 09:54 development.log -rw-r--r-- 1 user...
...This behavior is a built-in feature of Ruby's standard Logger class, which Rails uses by default. To control the maximum file size, set config.log_file_size in your...
...an empty exclusion list returns no records at all! See below for better implementations. Rails 4+ Use the .not method to let Rails do the logic # Good User.where.not(id: []).to...
=> SELECT "users".* FROM "users" WHERE "users"."id" NOT IN (1, 2) Rails < 4 Before Rails 4, you needed to work around this yourself: # Good excluded_ids.blank? ? User.all : User.where("id...
Why Rails has multiple schema formats When you run migrations, Rails will write your current database schema into db/schema.rb. This file allows to reset the database schema without running migrations...
...by running rails db:schema:load. The schema.rb DSL can serialize most common schema properties like tables, columns or indexes. It cannot serialize more advanced database features, like views, procedures...
Rails wraps your parameters into an interface called StrongParameters. In most cases, your form submits your data in a nested structure which goes hand in hand with the strong parameters...
...expect/permit/require when passing them to e.g. ActiveRecord. Note that expect is only available from Rails 8. There are cases where it might be fine to read directly, like: # Okay
TL;DR: Rails ships two methods to convert strings to constants, constantize and safe_constantize. Neither is safe for untrusted user input. Before you call either method you must validate...
...w[User Post Test]) if class_name class_name.safe_constantize.new # either User, Post or Test else Rails.logger.error "This should not happen!" end Handling unresolvable constants The safe_constantize method is defined in...
Rails ships with a default menu of libraries and conventions — its creators call it "Omakase", the chef's choice. Like many companies, we don't follow that menu blindly. Over...
...we differ and why, so you won't be confused when a tutorial, a Rails guide or a freshly generated app looks different from our projects. Important
...response time of a notoriously slow JSON API endpoint that was backed by a Rails application. While every existing app will have different performance bottlenecks and optimizing them is a...
The data flow examined in this card are based on an example barebone rails app, which can be used to reproduce the results. I tried to mimic the case...
When you want to group rails models of a logical context, namespaces are your friend. However, if you have a lot of classes in the same namespace it might be...
'accounting_' end end class Accounting::Invoice < ApplicationRecord ... end class Accounting::Payment < ApplicationRecord ... end Rails will be able to derive the table name accounting_invoices for Accounting::Invoice. Note
While working on a Rails application, your code base will grow a collection of different file types including: Ruby (business logic) HTML fragments (layouts and views) CSS/Sass/SCSS (styles) JavaScript (client...
...files which are often summed up as assets. You might already have noticed that Rails modifies those assets before delivering them to the client. For example, you'll never see...
Rails default config uses the ActiveSupport::Cache::NullStore and disables controller caching for all environments except production: config.action_controller.perform_caching = false config.cache_store = :null_store If you want to test caching...
path end end RSpec.configure do |config| config.include CachingHelpers end 3. Now stub the Rails cache and clear it before each example: RSpec.describe SomeClass let(:file_cache) { ActiveSupport::Cache.lookup_store...
...characters that have a particular meaning in URLs, like & or =. If you are using Rails URL helpers like movies_path(:query => ARBITRARY_STRING_HERE), Rails will take care of the...
...web application remembers a user between requests. This lesson covers how cookies work, how Rails sessions build on them, and what signed, encrypted and SameSite cookies protect against. Important
...lifetime and scope (expiry, domain, path, Secure, HttpOnly, SameSite). You can explain how a Rails session builds on cookies, and why a "session cookie" is something else. You can explain...
Here is how to disable it, or how to add it to your Rails console. Welcome banner Modern versions of irb show a pretty banner which prints
...have one yet) and add: IRB.conf[:SHOW_BANNER] = false How to enable for the Rails console You like the banner and want to see it for a rails console as...
When your Rails application server raises error, Capybara will fail your test when it clears the session after the last step. The effect is a test that passes all steps...