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

...posts with a limited number of tags. The following chapters explain different approaches in Rails, how you can assign such an association via HTML forms. In most cases you want...

...with assignable values. The basic setup for all options looks like this: config/routes.rb Rails.application.routes.draw do root "posts#index" resources :posts, except: [:show, :destroy] end db/migrate/20230510093740_create_posts.rb class CreatePosts < ActiveRecord::Migration...

...scope :all_tags, -> (tags){ where('tags @> ARRAY[?]', tags) } end Document.create(title: "PostgreSQL", tags: ["pg","rails"]) Document.any_tags('pg') Document.all_tags(['pg', 'rails']) Migration: class CreateDocuments < ActiveRecord::Migration def change

Rails' Strong Parameters enable you to allow only specific values from request params to e.g. avoid mass assignment. Usually, you say something like params.permit(:email, :password) and any extra parameters...

Rails' I18n API keeps user-facing strings, formats and error messages in locale files. This lesson covers how to use it, why it is useful even for single-language apps...

...for view-scoped keys like t('.title') 📄 Guide to localizing a Rails application — our card 📄 rails-i18n — Rails' standard translations per language; we copy and customize the locale files

makandra dev

...after_logout idp_sign_out] end Unsafe redirect when trying to log out Since Rails 7 you need to pass allow_other_host: true to redirect_to to allow a...

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

tl;dr Prefer request specs over end-to-end tests (Capybara) to joyfully test file downloads! Why? Testing file downloads

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

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

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

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

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.

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

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

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

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

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

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

...travels from the browser to the server (a multipart form post) and where a Rails app can store it. You can explain where uploads live on our servers — in a...

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

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

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