edgeapi.rubyonrails.org

The linked article suggests an interesting way to speed up tests of Rails + Postgres apps: PostgreSQL allows the creation of “unlogged” tables, which do not record data in the PostgreSQL...

...the project might need to re-recreate their test databases like so: bundle exec rails parallel:drop && bundle exec rails parallel:prepare

...some cases, a viable workaround is to turn your images into inline attachments. Note Rails provides a simple mechanism to achieve this: https://guides.rubyonrails.org/action_mailer_basics.html#making-inline-attachments This documentation makes it look...

...It is recommended to watch for a feature flag, see below. return version unless Rails.config.feature_inline_email_images # `attachments` is provided by Rails, see the linked documentation above # URLs should...

...into a database console, run SET GLOBAL query_cache_type=OFF; and restart your rails server. You can also disable the cache on a per query basis by saying

...SQL_NO_CACHE * FROM ... You also probably want to disable Rails internal (per-request) cache. For this, wrap your code with a call to ActiveRecord::Base.uncached. For example, as an...

Since Rails 6+ you can use before? and after? to check if a date/time is before or after another date/time. Example christmas = Date.parse('24.12.2022') date_of_buying_a...

github.com

...TILs on many topics that might be interesting for most of us. (e.g. Ruby, Rails, Git, Unix..) Ruby Here is an excerpt of all the Ruby TILs that were new...

blog.saeloun.com

...want to find all Decks without any Card or all Cards without a Deck. Rails 6.1+ Rails 6.1 introduced a handy method ActiveRecord#missing to find records without given associations...

ON "decks"."id" = "cards"."deck_id" WHERE "decks"."id" IS NULL Older Rails versions If you don't have Rails 6.1 yet, you can use this not-so...

SQL end Usage example: insert_record 'users', name: 'joe', age: 15 Also see Rails: Talking to the database without instantiating ActiveRecord objects...

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

To ensure Spring is not running: bin/spring stop pkill -f spring To prevent Spring from starting again: export DISABLE_SPRING...

Let's say you have a form that you render a few times but you would like to customize your...

When deploying Rails applications you might have noticed that JS and CSS are not cached by all browsers. In order to force Apache to add expiry dates to its response...

...when I change a file? Changed stylesheets and javascripts will always be reloaded because Rails appends a screen.css?1234567 timestamp to the paths. Background images referred to from the CSS...

...in our tests for sequential test execution but not for parallel test execution. And Rails requires you to set the config.cache_classes = false if you are using Spring in tests...

...With our setup, this would raise the following error in cucumber-rails for parallel test executions due to some legacy database cleaner issue. WARNING: You have set Rails' config.cache_classes...

Most of our applications use CarrierWave for file uploads. CarrierWave has an integrated processing mechanism for different file versions with...

To read the Rails session from a Rack middleware, use env['rack.session']. It's an ActionDispatch::Request::Session object. class MyMiddlware def initialize(app) @app = app end def call(env...

...status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end You may not be able to write to...

If your irb or rails console keeps randomly crashing and you can't figure out why then you can try to disable multi-line autocomplete...

Rails comes with grouped_collection_select that appears to be useful, but isn't. As an alternative, consider the flat_grouped_collection_select found below. It takes a third argument...

The benefit of the Rails asset pipeline is that it compiles your stylesheets and javascripts to a single file, respectively. However, the consequences are startling if you don't understand...

...gave every library its own "root" folder. First, add this line to your config/initializers/assets.rb: Rails.application.config.assets.paths += Dir["#{Rails.root}/vendor/asset-libs/*"].sort_by { |dir| -dir.size } This will tell Rails about the custom asset...

...several gems that help to you do that, like Sidekiq or Resque. With newer Rails you can also use ActiveJob as interface for a background processing library. See here for...

end and a features/support/active_job.rb with: # Jobs should be worked off immediately in tests Rails.application.config.active_job.queue_adapter = :inline

...nicer to read, but has horrible security implications in some versions of Ruby on Rails. Affected versions Version Affected? Remedy 2.3.18 yes Use chain_safely workaround 3.0.20 no

Use Rails LTS 3.2 with hardened configuration 4.0.x ??? ??? 4.2.3 no Example When you chain two scopes with hash conditions on the same attribute, the second scope will overwrite...

dev.37signals.com

The author describes his little journey in hunting down a memory leak. Maybe his approach and tooling may one day...

...a situation in which I received the yarn integrity check warning when starting the rails console even though everything was up to date and correct versions in use.

I tried starting the rails console without switching to the correct node version first and received the yarn integrity warning. warning Integrity check: System parameters don't match...

paweldabrowski.com

The linked content includes a few design patterns implemented with Ruby on Rails. What is the card indented to achieve? You can use the pattern names for code reviews, so...

stackoverflow.com

Create, or edit your ~/.irbrc file to include: require 'irb/ext/eval_history' # was 'irb/ext/save-history' for versions prior to Ruby 3.3 IRB.conf[:SAVE...

There is a way to use multiple databases in Rails. You may have asked yourself how you're able to keep your test databases clean, if you're running multiple...

...records to check if the migration works properly with those. after_initialize :readonly!, unless: -> { Rails.env.test? } end When defining multiple adapters in your database.yml, Rails needs to decide which one to...