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

When your Rails application is using Redis as its cache store, this is how you can list existing keys: Check: Rails.cache should return an ActiveSupport::Cache::RedisCacheStore. Rails.cache.redis.with(&:keys) lists...

...root path: xsendfile: unable to find file: /tmp/foo20110721-28050-1h104da-0 The reason for this is that Rails 3 uses X-Sendfile for file downloads and Apache is only allowed to transfer files...

...with HSTS. The HSTS part is important. Use a reliable authentication solution, e.g. Compose Rails authentication primitives, Clearance or Devise. Don't start from scratch (see bottom).

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.

...a good default to add a unique index on the foreign key when using Rails’ has_one relationship. This ensures the database enforces the 1:1 constraint and raises an...

github.com

...This is arguably a good idea. As a workaround, use stub_const in your Rails specs like this: stub_const "#{SomeClass}::CONST", 'test' This will invoke Rails' autoloading and fix...

Why and what to test 📘 Chapter "The value of tests" from Growing Rails Applications in Practice (in our library) 📄 Write tests. Not too many. Mostly integration. — the reasoning...

...strategy that fits — the different test-suite shapes side by side 📄 Guidelines for Testing Rails Applications — the same discussion for a Rails/RSpec suite RSpec and Capybara 📘 Everyday Rails Testing with...

...to your DB schema. Ignore the column With ignored_columns you can prevent your Rails models from generating accessor methods for these columns: class User < ApplicationRecord self.ignored_columns += [:legacy_field...

island94.org

Rails 5.2 soft-deprecated the storage of secrets in secrets.yml in favor of a new thing, credentials.yml.enc. Rails 7.1 deprecated secrets and Rails 7.2 finally removed it. In our permissions...

...for existing applications it may be appropriate to keep using secrets.yml. Restoring secrets in Rails 7.2+ Restoring Rails.application.secrets is really simple, thanks to config_for. Simply add this to config/application.rb...

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

#pluck is commonly used as a performant way to retain single database values from an ActiveRecord::Relation Book.pluck(:title, :price...

...notice this until it's too late. We investigated multiple gems and found that rails_performance (https://github.com/igorkasyanchuk/rails_performance) provides a lot of valuable information with very little setup cost...

stackoverflow.com

To reload a single-item association in Rails 5+, call #reload_ : post.reload_author In older Railses you can say post.author(true...

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

makandra dev

...reuse your existing factories instead of using the UI or creating records in the Rails console. This approach saves time and gives you useful defaults and associations right out of...

You can use FactoryBot directly in the Rails console like this: require 'factory_bot_rails' # Not needed if the factory_bot_rails gem is in the :development group...

Rails slightly changed the fragment cache implementation from Rails 7.0 to Rails 7.1. Unfortunately, this is incompatible with how Haml 5 patches Action View buffers. I tried turning a String...

...an ActionView::OutputBuffer, but this brought up other issues. Conclusion While we have a Rails 7.2 application successfully running with Haml 5, Rails applications with fragment caching need to upgrade...

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

Ruby and Rails have several methods for creating a new object that looks like another: clone, dup, deep_dup. When using them you should be aware of their differences so...

makandra dev

...ALLOW_REMOTE_DATABASE_URL: 'true' DATABASE_URL: postgres://postgres:postgres@localhost:5432/test PGTZ: 'Europe/Berlin' RAILS_ENV: test TZ: 'Europe/Berlin' strategy: matrix: partition: [ 0, 1, 2, 3 ] # Keep in sync with...

...uses: actions/checkout@v4 - uses: ./.github/actions/setup-node - uses: ./.github/actions/setup-ruby - name: Setup database schema run: bundle exec rails db:create db:schema:load - name: Precompile assets run: bundle exec rails assets:precompile

makandra dev

...for consumption in browsers. Webpacker is a wrapper around webpack that handles integration with Rails. This is a short introduction. Installation If you haven't already, you need to install...

...x is still current! in your Gemfile. Run bundle install Finally, run bundle exec rails webpacker:install Alternatively, you can add webpacker from the start when creating a new Rails...

Rails 3, 4, 5, 6 config/application.rb config/environment.rb before the initialize! call (we don't usually edit this file) The current environment, e.g. environments/production.rb Gems Vendored plugins All initializers in config/initializers...

...initialize! call (we don't usually edit this file) Your own code from app Rails 2 Code in config/preinitializer.rb (if it exists) environment.rb, code above the Rails::Initializer.run block (put...

...end-to-end test for every small requirement. After we integrated Jasmine into a Rails app we often add an E2E test that opens that Jasmine runner and expects all...

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