...consume GBs of memory bringing down our servers. The solution Just use .preload instead. Rails will use separate queries to preload the data. This cannot lead to a cross product...

options: { search: 'window.toString() === \'[object GjsGlobal]\'', replace: 'window.toString() === \'[object Window]\'' } }] }) Fix for ESBuild / jsbundling-rails Add the package esbuild-plugin-text-replace to your package.json. Now add the following plugin...

makandra dev
railsforzombies.org

Learning Rails for the first time should be fun, and Rails for Zombies allows you to get your feet wet without having to worry about configuration. You'll watch five...

...videos, each followed by exercises where you'll be programming Rails in your browser...

Rails 8 provides a new way of doing things after the current transaction, without defining a model "global" after_commit callback. def do_something update_column(:foo, "bar")

...update_column(:foo, "bar") ActiveRecord::Base.current_transaction.after_commit { send_email(foo: "bar") } ActiveRecord::Base.current_transaction.after_rollback { Rails.logger.warn("rollback") } # after_rollback is also supported end If you call current_transaction.after_commit in a nested...

...changelog_path = File.expand_path('../CHANGELOG.md', __dir__) Ruby < 2.0 changelog_path = File.expand_path('../../CHANGELOG.md', __FILE__) Rails changelog_path = Rails.root.join('CHANGELOG.md...

If you get an error message like that you are missing the Aspell files a specific language:

...only list versions that are allowed by your Gemfile requirements (e.g. does not show rails update to 6 if your Gemfile has the line gem 'rails', '~>5.2'). I also experienced...

sudo gem install rails --version="=1.2.3" rails _1.2.3_ new-project-folder

...you UTC objects whose to_s(:db) may not convert properly. Legacy behavior in Rails 2.3 It's been briefly mentioned in the random list of ActiveSupport goodies, but please...

...remember to always use Time.current instead of Time.now, etc. Why? Because of the way Rails and MySQL deal with time zones you would need to take care to use Time.zone.now...

robots.thoughtbot.com

Declare an enum attribute where the values map to integers in the database, but can be queried by name.

everydayrails.com

I recently had a need to demonstrate a data-heavy application to potential customers. Demonstrating the application with bogus numbers...

...loads a new page. The browser does almost nothing but display. This is how Rails works out of the box: simple, robust, fast to build, easy to test with a...

...opens overlays, keeps scroll positions. Libraries in this family: Unpoly (our choice), Hotwire/Turbo (the Rails default), htmx. You keep the MPA's simplicity — one source of truth on the server...

...agent can't infer from the code: the test command, conventions that differ from Rails defaults, gotchas. It is not the place for things the agent already does right, or...

...stack isn't the default one, and an agent reaches for the default (Our Rails stack, and why it isn't Omakase). Judging the design. Whether this is simple, whether...

makandra dev

...query -> query embedding -> kNN search -> ranked pages | +--------------------------------------------------------------------+ See: How to add RAG to your Rails application Full-text keyword search (BM25) Full-text search splits each document into tokens (words...

...calls in local and CI tests. See also How to add RAG to your Rails application: vector search end-to-end. You don't need a vector database to build...

...accidentally translates the query. It might be a good idea to cache the result (Rails.cache) for some time so a page reload doesn't re-call the LLM. Authorize the...

...to Hybrid search for the trade-offs, or How to add RAG to your Rails application to get started on the vector branch...

justinfrench.com

If you’re testing the behavior of deprecated code in your Ruby project, the warning messages littered throughout your spec...

gist.github.com

The differences are subtle. You probably want to use Time, except when you want to use DateTime. See the attached...

sudo apt-get install unzip rake rails:freeze:edge RELEASE...

...Always convert to a symbol, otherwise you'll have all kinds of fun. Newer rails / activerecord (at least 5.2) will throw an association names must be a Symbol (ArgumentError) error...

...few examples, where you configure some library via a block. One example is the Rails configuration: Rails.application.configure do |config| config.enable_reloading = false end This card describes a simple example on...

...You can use ActiveSupport::Configurable instead of the Configuration class. When you are using Rails with Zeitwerk and the code for e.g. FooClient lives in a folder, that is loaded...

...already shipping as custom elements For example Trix from Basecamp (integrated as ActionText in Rails 6). By choosing custom elements as their delivery method, they work in all JavaScript frameworks...

...alotting time. This is a refactoring similar to removing resource_controller (but not a Rails upgrade). Grep for $. This will show you all the affected lines of code. Refactor functions...

...method is defined even when metaprogramming defined it, e.g. with Method#source_location, the Rails API docs or your IDE. You can write a monkey patch that wraps an existing...

...keyword args in Ruby 3.0 — our card: why argument forwarding needs care 📄 ActiveSupport::Concern — Rails API docs: what it adds to a plain module 📄 Modularity — our gem for parameterized modules...

...up repetitive expectations in your specs. Unfortunately the default directory structure generated by rspec-rails has no obvious place to put custom matchers or other support code. I recommend storing...

...to all specs, put the following into your spec_helper.rb, above the RSpec.configure block: Dir[Rails.root.join("spec/support/**/*.rb")].sort.each {|f| require f} Also see where to put shared example groups...

...already know. Just ask. Code smells and refactoring ▶️ All the Little Things — Sandi Metz, RailsConf 2014; turning a knot of conditionals into small objects, step by step 📘 Ruby Science — thoughtbot...

...free PDF; a catalog of Rails code smells, each with the refactoring that fixes it 📄 Code smells and the refactoring catalog — the vocabulary: feature envy, long parameter lists, inappropriate intimacy...