Ruby / Rails errors

Ruby and Ruby on Rails errors — NoMethodError, ActiveRecord, migrations, routing and authenticity tokens.

CodeErrorWhat it means
ActiveRecord::PendingMigrationError Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate The database schema is behind the migration files in the app.
ArgumentError: missing keyword / unknown keyword Ruby: ArgumentError: missing keyword: :name / unknown keyword: :nmae A method requiring keyword arguments was called without them, or with a misspelt keyword.
LoadError: cannot load such file Ruby: LoadError: cannot load such file -- nokogiri (or: cannot load such file -- bundler/setup) `require` couldn't find the file/gem — it isn't installed, not in the Gemfile, or the load path is wrong.
Your Ruby version is X, but your Gemfile specified Y Bundler: Your Ruby version is 3.1.2, but your Gemfile specified 3.3.0 `.ruby-version`/the Gemfile `ruby` line requires a different Ruby than the one running.
CORS blocked in Rails API (rack-cors) Browser: Access to fetch at 'http://localhost:3000/api/items' from origin 'http://localhost:5173' has been blocked by CORS policy — Rails The browser blocks calls from your front end to the Rails API because CORS headers are missing.
ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity) A non-GET request arrived without a valid CSRF token for the session.
PG::DuplicateColumn / Duplicate column name (migration) Rails: ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR: column "status" of relation "orders" already exists A migration tried to add a column/table/index that already exists.
PG::UndefinedTable: relation does not exist Rails: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "users" does not exist Rails queried a table that isn't in the connected PostgreSQL database.
ArgumentError: wrong number of arguments (given 1, expected 2) Ruby: ArgumentError: wrong number of arguments (given 1, expected 2..3) A method was called with more or fewer arguments than it accepts.
undefined method for nil Ruby: NoMethodError: undefined method `x' for nil (nil:NilClass) You called a method on nil — the object you expected (a record, hash value, param) wasn’t there.
Failed to build gem native extension Ruby: ERROR: Failed to build gem native extension. current directory: /gems/pg-1.5.4/ext/pg — An error occurred while installing pg A gem with C code couldn't compile, usually because a system library or header is missing.
ActiveRecord::ConnectionNotEstablished Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found ActiveRecord has no database connection configured or established for this process.
ActiveRecord::IrreversibleMigration Rails: ActiveRecord::IrreversibleMigration — This migration uses remove_column without a type; db:rollback can't reverse it `rails db:rollback` can't undo the migration because it contains an operation Rails can't invert.
ActiveRecord::RecordNotUnique: duplicate key value Rails: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" A unique index rejected an insert/update because the value already exists.
FrozenError: can't modify frozen String Ruby: FrozenError: can't modify frozen String: "abc" You tried to change an object that's frozen — string literals under `# frozen_string_literal: true`, constant…
NameError: undefined local variable or method Ruby: NameError: undefined local variable or method 'x' for main:Object Ruby saw a bare identifier that is neither a local variable nor a method on the current object.
Bundler: Could not find gem in locally installed gems Bundler: Could not find gem 'rails (~> 7.1)' in locally installed gems / Could not find rails-7.1.0 in any of the gem sources listed in your Gemfile A gem from the Gemfile/Gemfile.lock isn't installed (or isn't available at that version).
A server is already running. Check /tmp/pids/server.pid Rails: A server is already running (pid: 12345, file: /app/tmp/pids/server.pid). Exiting Rails thinks another server is running because a stale `server.pid` exists (often after a crash or in Docker).
AbstractController::DoubleRenderError Rails: AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action) An action called `render`/`redirect_to` more than once.
ActionController::RoutingError: No route matches Rails: ActionController::RoutingError (No route matches [GET] "/users/new") The request path/method doesn't match any route in `config/routes.rb` (a 404 in production).
ActiveRecord::RecordNotFound: Couldn't find X with 'id'= Rails: ActiveRecord::RecordNotFound: Couldn't find User with 'id'=42 `find`/`find_by!` didn't find a row, so Rails raises (and renders a 404 in production).
Missing encryption key to decrypt file with Rails: ArgumentError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to config/master.key or put it in the ENV['RAILS_MASTER_KEY'] Rails needs `config/master.key` or `RAILS_MASTER_KEY` to read credentials, and neither exists.
RSpec::Expectations::ExpectationNotMetError: expected X got Y RSpec: expected: 200 got: 404 (compared using ==) — RSpec::Expectations::ExpectationNotMetError An RSpec `expect` assertion didn't hold: the actual value differs from what the test expected.
Bundler could not find compatible versions for gem Bundler: Bundler could not find compatible versions for gem "activesupport": In Gemfile: rails (= 7.1.0) depends on activesupport (= 7.1.0) Two gems in your Gemfile require incompatible versions of a shared dependency.
ActionController::UrlGenerationError: No route matches {action...} missing required keys Rails: ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"users", :id=>nil}, missing required keys: [:id] A URL helper (`user_path(@user)`) was called without a value Rails needs (usually `nil` object).
ActionView::Template::Error: undefined method for nil in view Rails: ActionView::Template::Error (undefined method `name' for nil:NilClass): app/views/users/show.html.erb:3 A view called a method on `nil` (or an undefined helper), so rendering failed — the error is wrapped in `Acti…
ActiveSupport::MessageEncryptor::InvalidMessage Rails: ActiveSupport::MessageEncryptor::InvalidMessage (credentials.yml.enc can't be decrypted — wrong master.key) Rails couldn't decrypt `credentials.yml.enc` (or a signed/encrypted cookie) because the key is wrong or the d…
PG::ConnectionBad: could not connect to server Rails: PG::ConnectionBad: could not connect to server: Connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? Rails can't reach PostgreSQL — the server is down, wrong host/port/socket, or credentials/pg_hba block it.
Zeitwerk::NameError: expected file to define constant Rails: Zeitwerk::NameError: expected file app/models/user_profile.rb to define constant UserProfile, but didn't Rails autoloading found a file whose name implies a constant the file doesn't define.
rake aborted! Don't know how to build task Rake: rake aborted! Don't know how to build task 'db:migrat' (See the list of available tasks with `rake --tasks`) Rake doesn't know the task name — a typo, a missing Rakefile, or a gem/engine not loaded.
Redis::CannotConnectError (Sidekiq/Rails) Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) Sidekiq or the Rails Redis cache/cable couldn't connect to Redis.
OpenSSL::SSL::SSLError: certificate verify failed (Ruby) Ruby: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) Ruby's HTTP client (Net::HTTP, Faraday, gem install) couldn't verify the server's certificate.
FactoryBot::DuplicateDefinitionError: Factory already registered FactoryBot: FactoryBot::DuplicateDefinitionError: Factory already registered: user Two factory definitions use the same name (or files are loaded twice).
ActionController::UnknownFormat Rails: ActionController::UnknownFormat — UsersController#show is missing a template for this request format and variant The controller has no template or `respond_to` handler for the requested format (HTML/JSON/etc.).
Missing secret_key_base for 'production' environment Rails: ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit` Production boot needs a `secret_key_base` to sign/encrypt cookies, and none is configured.
Rack::Timeout::RequestTimeoutException Rails: Rack::Timeout::RequestTimeoutException: Request ran for 15001ms, exceeding the 15000ms timeout (Heroku H12) A request took longer than `rack-timeout`'s limit (or Heroku's 30 s router timeout), so it was aborted.
Yarn executable was not detected in the system Rails: Yarn executable was not detected in the system. Download Yarn at https://yarnpkg.com/en/docs/install Rails asset tasks (`assets:precompile`, webpacker/jsbundling) need Node and Yarn but they're not installed/on…
TypeError: nil can't be coerced into Integer Ruby: TypeError: nil can't be coerced into Integer / String can't be coerced into Integer Arithmetic combined a number with `nil` (or a String) which Ruby can't convert automatically.
ActionController::ParameterMissing: param is missing or the value is empty Rails: ActionController::ParameterMissing: param is missing or the value is empty: user `params.require(:user)` found no `user` key (or it was blank), so Rails responds 400.
ActiveModel::ForbiddenAttributesError (strong parameters) Rails: ActiveModel::ForbiddenAttributesError You passed raw `params` to `new/create/update`, but strong parameters require permitting attributes first.
ActiveRecord::ReadOnlyRecord Rails: ActiveRecord::ReadOnlyRecord: Order is marked as readonly You tried to save a record that was loaded as read-only (e.g. via `joins` in old Rails or `readonly` scope).
ActiveRecord::StaleObjectError (optimistic locking) Rails: ActiveRecord::StaleObjectError: Attempted to update a stale object: Order Two users/processes updated the same record; the second save failed the `lock_version` check.
TypeError: no implicit conversion of nil into String Ruby: TypeError: no implicit conversion of nil into String A String method (`+`, `File.join`, `Array#join` usage) received `nil` instead of a string.
Nokogiri: could not find a platform gem / libxml2 build error Bundler: Your bundle only supports platforms ["x86_64-linux"] but your local platform is arm64-darwin / Could not find gem 'nokogiri (1.16.0-arm64-darwin)' The lockfile has no Nokogiri build for the current platform (precompiled "native" gems are per platform).
ActionView::MissingTemplate: Missing template Rails: ActionView::MissingTemplate (Missing template users/show, application/show with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}) The action tried to render a view that doesn't exist for the requested format/handler.
ActiveRecord::RecordInvalid: Validation failed Rails: ActiveRecord::RecordInvalid: Validation failed: Email can't be blank, Name is too short `save!`/`create!`/`update!` raised because validations failed.
Mysql2::Error: Unknown column in field list Rails: ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'users.nickname' in 'field list' The query references a column that doesn't exist in the table (missing migration, typo or stale schema cache).
ActionMailer: SMTP From address may not be blank / Net::SMTPAuthenticationError Rails: ArgumentError: SMTP From address may not be blank: nil / Net::SMTPAuthenticationError: 535 5.7.8 Username and Password not accepted Rails mail delivery failed — missing `from`, wrong SMTP settings, or rejected credentials.
Sprockets::Rails::Helper::AssetNotPrecompiled Rails: Asset `application.js` was not declared to be precompiled in production / The asset "application.css" is not present in the asset pipeline A layout references an asset that Sprockets doesn't know to compile or can't find.
Puma: Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE) Rails/Puma: Errno::EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 3000 Another process already listens on the port Puma wants.
ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678) You assigned the wrong kind of object (or an id string) to an association.
ActiveRecord::Deadlocked: PG::TRDeadlockDetected Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected Two transactions locked rows in opposite orders, so PostgreSQL aborted one.
NameError: uninitialized constant Ruby: NameError: uninitialized constant UsersController::User (Did you mean? Users) Ruby (or Rails autoloading) couldn't find a class or module with that name in the current scope.