...table that is missing them. You can use the add_timestamps macros for that. Rails >= 4.2 Since Rails 4.2 add_timestamps also adds a NOT NULL constraint by default. So...

...SET updated_at = '#{time}'" # Restore NOT NULL constraints to be in line with the Rails default change_column_null :shows, :created_at, false change_column_null :shows, :updated_at, false...

When dealing with time zones in Rails, there is one key fact to keep in mind: Rails has configurable time zones, while Ruby is always in the server's time...

...actually disable time zones, because their existence is a fact. You can, however, tell Rails the only single time zone you'll need is the server's. config.time_zone = "Berlin...

...projects, which is being actively maintained and has test coverage for all versions of Rails...

Several Rails migration methods accept index: true as an option to create an index. In some cases (like #add_column), this option is silently discarded. Know what you are doing...

...positive" btree (positive) "index_examples_on_user_id" btree (user_id) So what happened? Rails created indexes for all fields that we added inside our create_table statement.

...readable form of the attribute: Person.human_attribute_name(:first_name) # => "First name" By default Rails will use String#humanize to format the attribute name, e.g. by replacing underscores with spaces...

...If no explicit translation is found, String#humanize is used. This card explains where Rails will look for custom attribute name translations in your locale files. Tip

It might sometimes be useful to check whether your Rails application accesses the file system unnecessarily, for example if your file system access is slow because it goes over the...

...which logs all system calls performed by a process. To do this, start your rails server using something like DISABLE_SPRING=1 strace -e trace=file -f bin/rails s

If you're suffering from a huge de.yml or similiar file, cry no more. Rails lets you freely organize your dictionary files in config/locales. My organization works like this: config/locales/rails.de.yml...

...modified Rails boilerplate config/locales/faker.de.yml modified Faker boilerplate config/locales/models.de.yml model names, attribute names, assignable_value labels config/locales/views.de.yml text in the GUI config/locales/blocks.de.yml if you organize your CSS with BEM you can...

makandra dev

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

...with resources as well, e.g. resources :examples, path: 'demonstration' Two macros for namespacing routes Rails offers two macros for namespacing routes. As its name suggests, namespace is the tool for...

api.rubyonrails.org

In Rails 7.2. the feature ActiveRecord.after_all_transactions_commit was added, for code that may run either inside or outside a transaction (we have a special card for nested transactions...

...for custom handling, which now can be replaced by the build-in functionality of Rails. Note: This doesn't solve issues, where you want to have a specific order of...

...apply a significant score penalty. Here is how to do that automatically. Add premailer-rails to your Gemfile and bundle. Done! premailer-rails will automatically generate a text part for...

Actually, you may want to configure premailer-rails, and maybe tweak your HTML e-mail views a bit. Here are some suggestions. Open Rails' ActionMailer Previews and you will...

Rails credentials are a way to store secrets in an encrypted YAML file. Usage is simple: each key in the credentials file becomes a method on Rails.application.credentials, returning the corresponding...

# Credentials file file_storage_secret: superstrongsecret # Somewhere in the application FileStorage.secret = Rails.application.credentials.file_storage_secret Since credentials usually are different between environments, you can easily forget to define them for...

...rare cases it's helpful to redirect the Logger output temporary to e.g. STDOUT. Rails.logger = Logger.new(STDOUT) ActiveRecord::Base.logger = Logger.new(STDOUT) User.save! #=> D, [2025-09-08T11...

...FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]] Many frameworks in Rails have their own logger configuration and are set on boot. The example above configures the...

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.

...must be translated: Screens, mailer templates, PDF templates, helpers, sometimes models. Use the native Rails I18n API. Avoid Gettext if possible. Native I18n has good integration with Rails (you already...

...Rails framework can be overridden in locale dictionaries (e.g. config/locales/de.yml). There's an awesome gem rails-i18n that gives you default dictionaries for many languages. Note that even though all...

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

When Rails releases a new version of their gems, they also release a number of npm packages like @rails/activestorage or @rails/actioncable. Unfortunately Rails uses up to 4 digits for their...

...digits and a pre-release suffix. To map gem versions and npm versions, Rails is going to use a naming scheme like this: Gem version

makandra Curriculum

Read the Rails Guide about Active Record migrations Understand why we never use models in migrations. Checkout the repository Project Hero and read through some migrations in db/migrate. Find...

...files in the db/migrate folder. Read and understand How to write complex migrations in Rails Discuss with your mentor Instead of migrations, could we simply log into the production server...

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

You can improve your LIKE / ILIKE search queries in PostgreSQL by adding a GIN index with an operate class ("opclass...

...check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans it might still be a good idea to use...

guides.rubyonrails.org

...html_safe and translate them with = t('.text_html'). When you're localizing a Rails application, sometimes there is this urge to include a little HTML. Be it some localized...

...to learn more about &lt;em&gt;the corporation&lt;/em&gt;. Alright. Rails is being helpful here and saves you from accidentally injecting HTML into the page. But how...

...a has_many, has_one or belongs_to association, the :inverse_of option in Rails tells ActiveRecord that they're two sides of the same association. Example with a has...

...to :forum, inverse_of: :posts end Knowing the other side of the same association Rails can optimize object loading so forum and forum.posts[0].forum will reference the same object...

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

After Rails 8: The command loads the schema file (db/schema.rb or db/structure.sql) if existing and runs all pending migrations in the folder db/migrate/* afterwards This speeds up the command...