There are multiple ways to redirect URLs to a different URL in Rails, and they differ in small but important nuances. Imagine you want to redirect the following url...

...so that a tcp connection is used instead of a socket connection. Configure rails application to use the database development: adapter: mysql2 database: projectname_development encoding: utf8mb4 collation: utf8mb4_unicode...

It is very common to parse dates from strings. It seems obvious to use Date.parse for this job. However this...

github.com

When internationalizing your Rails app, you'll be replacing strings like 'Please enter your name' with t('.name_prompt'). You will be adding keys to your config/locales/*.yml files over...

postgresql.org

...in any structure. While its flexibility is great, there is no syntactic sugar in Rails yet. Thus, you need to manually query the database. Demo # Given a Task model with...

TL;DR: Pannellum is a small (~56 kB, own WebGL renderer, no three.js) equirectangular panorama viewer. The npm package has...

Running rails server will start a local server that you can access via http://localhost:3000. When you are working on multiple web apps, they will likely set cookies with...

...define it in a single place so switching it out will be easy. Modern rails versions will block hosts other than localhost by default. Therefore create an entry in config/environments/development.rb...

...gem with strategy :transaction, after_commit callbacks will not be fired in your tests. Rails 5+ Rails 5 has a fix for this issue and no further action is needed...

...Rails 3, Rails 4 Add the gem test_after_commit to your test group in the Gemfile and you are done. You don't need to change the database strategy...

So you want to organize your I18n using multiple .yml files but your Rails 4.1 application simply won't use any extra files in development? Spring is to blame.

Since Rails 7 you are able to encrypt database information with Active Record. Using Active Record Encryption will store an attribute as string in the database. And uses JSON for...

...need to configure your Active Record Encryption keys manually in the config/application.rb: config.active_record.encryption.primary_key = Rails.application.secrets.dig(:active_record_encryption, :primary_key) config.active_record.encryption.deterministic_key = Rails.application.secrets.dig(:active_record_encryption, :deterministic_key) config.active_record.encryption.key_derivation...

...say what you're trying to do. "What options does validates take in our Rails version?" gets a better answer than "how do validations work?". Most answers are right. When...

...Run an experiment. "Try it in the app and show me the result." A rails runner one-liner, a console session or a throwaway spec settles most questions in seconds...

...how the database executes a query (e.g. with EXPLAIN ANALYZE). You can read a Rails schema file and recognize ActiveRecord's naming conventions for tables and keys.

...minute live demo 📄 Differences between transactions and locking — clears up a common misunderstanding Rails and reference 📄 Rails Guides: Active Record Basics — Convention over Configuration — naming conventions for tables and columns...

...Ruby projects. These projects use a large number of different versions for Ruby, Rails and many gems. To be able to switch between projects easily, we must control every dependency...

...can explain that a gem may bring executables of its own, like rspec or rails, in addition to library code. You can explain what bundle exec does and when it...

Modern IRB has time measurement built in. measure # Enable measure :off # Disable Custom Should your version of IRB not offer...

reinteractive.com

...to configure omniauth-multi-provider to support multiple SAML identity providers for a single Rails app: To solve this, the omniauth-multi-provider gem acts as a dynamic wrapper around...

makandra dev

Just found out about a great feature in Rails that seems to be around since Rails 2. Start a console with the --sandbox (or -s) parameter: rails console --sandbox

...registered constants and the file references during the boot. Therefore you need to add Rails.autoloaders.log! at the end of your config/application.rb file. You could also run bin/rails zeitwerk:check for...

makandra dev

$ ruby -e "RubyVM::YJIT.enable; puts RubyVM::YJIT.enabled?" true The last variant is what Rails 7.2+ is doing after the boot process with its new default configuration. So if you...

...are on a current Rails version and didn't explicitly turn off YJIT, you are probably already using it. Keep in mind that Rails turns on YJIT after the boot...

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

...do it, and it's great, especially in combination with Sprockets (or Propshaft on Rails 7). You might be missing some convenience features, though. Here we cover one specific issue...

...Once you have started your development Rails server and esbuild with the --watch option (if you used jsbundling-rails to set up, you probably use bin/dev), esbuild will recompile your...

...travels from the browser to the server (a multipart form post) and where a Rails app can store it. You can treat an uploaded file like any other model attribute...

...the happy path, unit tests for versions and validations. You can explain how ActiveStorage, Rails' built-in alternative, differs from CarrierWave and why we default to CarrierWave. Resources

...without sending to the server, add this to config/initializers/sentry.rb inside the Sentry.init block: if Rails.env.development? # Use dummy transport to prevent actual transmission to Sentry config.transport.transport_class = Sentry::DummyTransport config.background_worker...

...this helper method after the Sentry.set_tags block: def log_sentry_event(event, hint) Rails.logger.error('SENTRY EVENT CAPTURED (LOCAL ONLY)') # Log anything that is interesting to you about the Sentry...

github.com

...All you need is a pretty print-stylesheet. How to use it from your Rails application You can have PDFKit render a website by simply calling PDFKit.new('http://google.com').to...

...separately before calling to_file. Alternatively you can use PDFKit::Middleware and all your Rails routes automagically respond to the .pdf format. This is awesome to get started fast, but...

In Capistrano 3, your Capfile requires 'capistrano/rails/migrations', which brings two Capistrano tasks: deploy:migrate and deploy:migrating. The former checks...