...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...

...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 add two chores...

Development environment setup Rails Composer Basically a comprehensive Rails Template. Prepares your development environment and lets you select web server, template engine, unit and integration testing frameworks and more.

...in minutes using an application template. With all the options you want! Code generators Rails Bricks A command line wizard. Once you get it running, it creates sleek applications.

...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

...best practices to maintain your tasks in larger projects. Rake Tasks vs. Scripts The Rails default is using rake tasks for your application tasks. These live in lib/tasks/*.

end end Example for a script: The slim ruby script: lib/scripts/user_export.rb: # bundle exec rails runner -e development lib/scripts/user_export.rb Gitlab::UserExport.new.export The main code lib/scripts/gitlab/user_export.rb: module Gitlab class UserExport

makandra dev

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...

Rails 7.1 added the normalizes method which can be used to normalize user input. It lets you define the fields you want to normalize and how to normalize them. In...

...validators or models (app/normalizers) you can use the following initializer. # config/initializers/normalizers.rb module Normalizers; end Rails.autoloaders.main.push_dir("#{Rails.root}/app/normalizers", namespace: Normalizers...

If you're using a Redis cache in Rails (e.g. :redis_cache_store), it's possible to configure additional parameters for your Redis connection. Example config for Rails 7.2

...too low value for timeouts can make your cache timeout too often. Note that Rails explicitly sets connect_timeout, read_timeout and write_timeout, which means that only configuring timeout...

If you are using the routing-filter gem in your Rails 7.1 app for managing URL segments for locales or suffixes, you will notice that the filters do no longer...

...and the necessary parameters are no longer extracted. That is because routing-filter patches Rails' find_routes-method to get the current path and apply its defined filters on it...

Rails' default logger prefixes each log entry with timestamp and tags (like request ID). For multi-line entries, only the first line is prefixed which can give you a hard...

...time when grepping logs. Example Rails.logger.info(<<~TEXT) Response from example.com: Status: 200 Body: It works! TEXT With that, the following is written to your log file.

api.rubyonrails.org

Rails offers a way to prepend (or append) view paths for the current request. This way, you can make the application use different view templates for just that request.

...action :prepare_views def index # ... end private def prepare_views if prepend_view_path Rails.root.join('app', 'views', 'special') end end end If is true, Rails will first look into app/views/special...

...older formatter API. Maybe there will be a fix for that eventually. Update cucumber-rails to >= 1.6.0: bundle update cucumber-rails Upgrade cucumber: bundle update cucumber Make sure you have...

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

This cards describes an example with a Github Client on how to keep your Rails application more maintainable by extracting domain independent code from the app/models folder to the lib...

...scenarios and not limited to API clients. Example Let's say we have a Rails application that synchronizes its users with the Github API: . └── app └── models ├── user │   ├── github_client.rb │   └── sychronizer.rb └── user.rb...

...need to decide, which configuration between different environment works good for you. By default Rails uses these settings for your application: require(:user) raises in all environments ActionController::ParameterMissing if...

...creating a database table for a join model without further importance, you can use Rails' create_join_table: class CreateSchoolsStudents < ActiveRecord::Migration[7.2] def change create_join_table :schools, :students...

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...

makandra dev

Postgres supports multiple built-in range datatypes: int4range int8range numrange tsrange (range with timestamp without timezone) tstzrange (range with timestamp...

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

By activating strict_loading you force developers to address n+1 queries by preloading all associations used in the index...

Rails is split into a large number of (sub-) frameworks. The most important and central of those are activesupport (extends the Ruby standard library) activerecord / activemodel (ORM for Rails)

...gem 'actionmailer', require: false) as well. When you look into the definition of rails/all (in railites-x.x.x/lib-/rails/all.rb) you can find the exact path for requiring the sub-frameworks.

...a cookie's "secure" flag do? Is it still relevant with HSTS? Look at Rails' API for managing cookies How do you set and delete cookies? What are signed cookies...

What are encrypted cookies and how do they work? Learn about Rails sessions (which are not the same as 'session cookies') Learn about the SameSite cookie attribute...

...so please feel free to contribute! General workflows The official guide How to upgrade Rails: Workflow advice Upgrading Rails: Example commits Upgrade to Rails 7 Don't use log level...

...debug in your production environments Rails 7.1: Take care of the new production log default to standard out Upgrade to Rails 6 Don't use log level :debug in your...

We are using assignable_values for managing enum values in Rails. Nevertheless Rails is adding more support for enum attributes, allowing to have a closer look at the current feature...

...to our still preferred option assignable_values. Active Record enum attribute interface By default Rails is mapping enum attributes to integers: class Conversation < ActiveRecord::Base enum :status, [ :active, :archived ]