First Day with Rails: Setup, Sessions, and a Confusing Error

Setting up a new Rails project means making some choices up front. Rails defaults to SQLite, so if you want Postgres you have to say so explicitly. It also bundles a lot of things you may not need right away—sprockets and JavaScript among them—and you can skip those during project generation to speed up the install. After a few attempts, the command that worked included flags for the Postgres database and for skipping both sprockets and JavaScript. Skipping those meant they could still be added later if needed.

rails new . -d postgresql --skip-sprockets --skip-javascript`

Two resources were particularly useful for getting a starter app running: DHH's original Rails talk from 2005 (worth watching if you haven't), and the official Rails "getting started" guide, which is short and clear.

A Baffling Error: undefined method 'user'

Early on, a simple piece of code threw a confusing error:

@user = User.new(user_params)
@user.save

The code called .save, but the error message claimed an undefined method user was being called:

undefined method `user' for #<User:0x00007fb6f4012ab8> Did you mean? super 

That didn't make sense at first—nothing in the code explicitly called a user method. After about 20 minutes of head-scratching, the issue came into focus by looking at the User model:

class User < ApplicationRecord
  has_secure_password

  validates :user, presence: true, uniqueness: true
end

The intention was to validate that every User had a username, and that usernames were unique. But a typo in the validation—writing user instead of username—was the culprit. Fixing that cleared the error.

What made this tricky to debug was that the stack trace pointed only at the @user.save line, never mentioning the mistyped validates :user declaration. That kind of indirection is part of the "Rails magic" experience—useful once you understand it, but puzzling when you're new to it.

Minimal User Management Without a Heavyweight Gem

For handling users in a toy app, the popular devise gem felt like more than was needed. Its README was overwhelming for a minimal use case. Instead, following an "Authentication from Scratch" guide worked well and required surprisingly little code. Rails already includes much of the underlying plumbing for users, and the guide showed how to wire it together.

One thing that stood out was Rails' built-in session management. By default, session data lives in a cookie on the user's machine. For larger data, sessions can be stored elsewhere, but the cookie-based default covers typical needs without extra setup.

It's a strange feeling to have sessions, cookies, and user handling working without fully understanding every layer underneath—but it's also part of the fun of getting a project moving quickly.