🌍 The Odin Project · flashcards
The Odin Project Databases, Ruby on Rails & Node.js Flashcards
50 question-and-answer cards covering Databases, Ruby on Rails & Node.js as it is examined in The Odin Project. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Databases, Ruby on Rails & Node.js deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
Why must you use Rails form helpers (like form_with) instead of hand-writing HTML forms?
Rails helpers automatically insert the CSRF authenticity token (without which Rails rejects non-GET submissions), set correct action/method attributes (including the _method override for PATCH/DELETE), and name fields so params arrive nested (e.g., params[:user][:name]).
In Rails form parameters, what does input name `user[email]` produce in the controller?
A nested hash in params: params[:user][:email]. The bracket naming convention groups related fields into one sub-hash so the whole set can be passed to a model at once.
What are strong parameters in Rails and how are they used?
A security mechanism requiring you to explicitly whitelist mass-assignable attributes, e.g. params.require(:user).permit(:name, :email); unpermitted attributes are dropped, preventing attackers from setting fields like `admin` via forged form data.
In a Rails controller, what is the difference between `render` and `redirect_to`?
`render` builds a response body from a view template within the current request (URL unchanged, instance variables available); `redirect_to` sends a 302 response telling the browser to make a brand-new request to another URL, discarding current instance variables.
How does data get from a Rails controller to its view?
Through instance variables: any @variable set in the controller action (e.g., @posts = Post.all) is automatically made available inside the corresponding view template.
In ERB templates, what is the difference between <%= %> and <% %>?
<%= %> evaluates the Ruby code and outputs the result into the HTML; <% %> evaluates the code without printing anything (used for logic like if statements and loops).
What are Rails partials and how are they rendered?
Reusable view fragments whose filenames start with an underscore (e.g., _form.html.erb); they are rendered with `render 'form'` or `render partial: 'user', locals: { user: @user }`, and collections can be rendered with `render @users`.
How do you declare a one-to-many association in Rails, and what does each model need?
The parent declares `has_many :posts` and the child declares `belongs_to :user`; the child's table must contain the foreign key column (user_id). The model with `belongs_to` is always the one holding the foreign key.
What are the two ways to set up a many-to-many association in Rails, and how do they differ?
`has_and_belongs_to_many` uses a bare join table with no model, while `has_many :through` uses a full join model (e.g., Appointment joining Physician and Patient). has_many :through is preferred when you need validations, callbacks, or extra attributes on the relationship.
What problem do the :class_name and :foreign_key options solve in Rails associations?
They let association names differ from model names, e.g. a Post with `belongs_to :author, class_name: "User", foreign_key: "author_id"` — Rails can no longer infer the model or key from the association name, so you specify them explicitly.
What does `dependent: :destroy` do on a has_many association?
When the parent record is destroyed, all its associated child records are also destroyed (running their callbacks), preventing orphaned rows that reference a deleted record.
What is `accepts_nested_attributes_for` used for in Rails?
Declared in a model (e.g., accepts_nested_attributes_for :addresses), it lets a parent record create/update associated records from a single form submission via a `addresses_attributes` parameter; the view uses `fields_for` to generate the nested inputs.
In a nested Rails form, what do the `_destroy` attribute and `reject_if` option do?
With allow_destroy: true, submitting `_destroy: 1` for a nested record deletes it; `reject_if` (e.g., :all_blank) skips creating nested records whose submitted fields are empty.
Why must passwords be stored as hashes rather than encrypted or plain text?
Hashing is one-way, so even if the database leaks, original passwords cannot be recovered (unlike encryption, which is reversible with a key). Rails uses bcrypt, a deliberately slow, salted hashing algorithm that resists brute-force and rainbow-table attacks.
What does `has_secure_password` give a Rails model?
Using the bcrypt gem and a `password_digest` column, it adds virtual `password` and `password_confirmation` attributes, validates their presence/match, stores only the bcrypt hash, and provides an `authenticate(password)` method that returns the user on success or false on failure.
Why does HTTP need sessions and cookies for authentication?
HTTP is stateless — each request is independent and the server retains nothing between them. Cookies are small key-value pairs the browser stores and sends with every request to that domain; sessions use a cookie (holding a session ID or signed data) to recognize the same user across requests, enabling 'staying logged in'.
In Rails, what is the difference between the `session` and `cookies` hashes?
`session` data is stored in an encrypted, tamper-proof cookie and is meant for temporary per-user state like the logged-in user's id (session[:user_id]); `cookies` writes plain browser cookies you control directly, which can persist long-term (cookies.permanent) and can be signed/encrypted explicitly.
What is Devise and what does it provide?
The most popular Rails authentication gem: a full engine providing sign-up, login/logout, password hashing, password reset emails, remember-me, account locking and confirmation, built from composable modules (database_authenticatable, recoverable, rememberable, etc.), plus helpers like current_user and authenticate_user!.
How does a Rails controller respond with either HTML or JSON from the same action?
With respond_to: e.g. `respond_to do |format| format.html; format.json { render json: @users } end` — Rails picks the block matching the request's requested format (URL extension or Accept header). `render json:` calls to_json on the object.
What is an Action Mailer in Rails and how do you send mail with it?
Mailers are classes (inheriting from ApplicationMailer) that work like controllers for email: methods set instance variables and call `mail(to:, subject:)`, views provide both HTML and plain-text templates, and you send with UserMailer.welcome_email(user).deliver_now (or deliver_later to queue it via Active Job).
What is the back end of a web application, and what are its three main components?
The server-side part the user never sees, responsible for storing, processing, and serving data. Its three core parts: the server (machine listening for requests), the application (server-side code handling requests and logic), and the database (organized persistent data storage).
What is Node.js?
Node.js is a JavaScript runtime built on Chrome's V8 engine that runs JavaScript outside the browser (on servers). It uses an event-driven, asynchronous, non-blocking I/O model: slow operations like file or network access are started, the program continues, and callbacks run via the event loop when the work completes.
What are the two module systems available in Node.js and their syntax?
CommonJS: require() to import and module.exports to export (Node's historical default). ES Modules (ESM): import/export syntax, enabled by using the .mjs extension or setting "type": "module" in package.json.
How do you debug a Node.js application beyond console.log?
Run `node inspect script.js` for the built-in terminal debugger, or `node --inspect` to open an inspector websocket that Chrome DevTools (chrome://inspect) or the VS Code debugger attach to; set breakpoints (or write `debugger;` in code), then step through and inspect variables. NODE_ENV/NODE_DEBUG and the util.debuglog utility help with log-based debugging.
What this deck covers
The Databases, Ruby on Rails & Node.js deck follows the The Odin Project Databases, Ruby on Rails & Node.js syllabus — 8 chapters and 38 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 6.3 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 253 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Databases, Ruby on Rails & Node.js flashcards FAQ
How many Databases, Ruby on Rails & Node.js flashcards are in this The Odin Project deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these The Odin Project flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Databases, Ruby on Rails & Node.js cards cover?
They follow the The Odin Project Databases, Ruby on Rails & Node.js syllabus — 8 chapters and 38 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.