My Knowledge Wiki
  • Introduction
  • My Stack
  • Sharing
  • Work
    • How I Want to Work
    • Hiring Process
  • Apps & Tools
    • Raycast
      • Extensions
    • Visual Studio Code
      • Theme
      • Extensions
    • Google Chrome
      • Theme
      • Extensions
    • iTerm 2
      • Theme
    • Fish
      • Plugins
    • Docker
      • Volumes
        • Mounting
    • Web Bundlers
      • Webpack
  • DevOps
    • Databases
      • Estimating Connections
    • Kubernetes
      • Terminology
      • kubectl Cheatsheet
      • Best Practices
      • Application Health Checks
      • Upgrades
      • Troubleshooting
      • Ruby on Rails
  • Awesome Products
  • Engineering Management
    • Overview
  • Software Architecture
    • Microservices
    • Event sourcing
    • Serverless
    • Centralized Authentication
  • Talks
    • Software Architecture
      • An Insider's Look at the Technology That Powers Shopify
      • Building Extensible Platforms
  • Documentation
  • Machine Learning
    • Terminology
    • Regression
    • Overfitting
  • Programming Languages
    • Constructs
    • Go
      • Syntax
    • Ruby
      • Ruby on Rails
        • Setup
        • Gotchas
        • Helpers
        • Libraries
        • Routing
        • Status Code Symbols
      • Debugging
        • Byebug
          • Cheatsheet
      • Libraries
      • Lazy Enumerators
      • Snippets
  • Version Control
    • Git
      • Conventions
        • Conventional Commits
        • gitmoji
  • Education
    • Programming & Computer Science
      • Courses
    • Design
      • Courses and Books
    • Frontend Development
  • HTTP
    • Status Codes
  • Design
    • Icons
      • Icon Sets
  • Arabic Content | محتوى عربي
    • Learning
      • مصادر لتعلم البرمجة و علوم الحاسب
    • Advice
      • إدارة المطورين: نبذة
      • نصائح تصحيح معتقدات خاطئة أمنيات للمبرمجين الجدد
  • Biology
    • Species
      • Ants
Powered by GitBook
On this page
  • ActiveRecord
  • database.yml
  1. Programming Languages
  2. Ruby
  3. Ruby on Rails

Gotchas

ActiveRecord

  • find raises an exception that if not handled, will result in controller endpoints returning 404.

  • find_by! is a variant that can be used to get the same behavior of find for find_by.

database.yml

If you try to have a generic database configuration controlled by environment variables, your database actions will run twice in development.

e.g.

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV['DATABASE_POOL'] %>
  host: <%= ENV['DATABASE_HOST'] %>
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USER'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

development:
  <<: *default

test:
  <<: *default

Since Rails by default runs migrations for the test environment when you're on development , when it tries to run them the RAILS_ENV will be development so it will actually run all the database actions on the development database again.

Instead ensure that you give specific and unique names for the development and test environments:

development:
  <<: *default
  database: my_app_development

test:
  <<: *default
  database: my_app_test
PreviousSetupNextHelpers

Last updated 5 years ago