skip to content

Action Controller Layer

What a Rails controller action does with a request: formats, strong parameters, filters, render and redirect, sessions, cookies, streaming and rescue_from. Every Rails interview touches it.

part ofRuby on Railsread it →
on this pageshow

explore

questions

page 2 of 2

After adding a portfolio_url field to a Rails job-application form, the value never saves and nothing errors; how do you diagnose it and stop it recurring?

level: seniorimportance: should knowfreq 40%

basics

~20 s

portfolio_url is missing from the allow-list, so strong parameters drop it silently. permit can log or raise unpermitted keys via action_on_unpermitted_parameters, but params.expect never reports them, so add the key and guard with request tests.

open as a page

In a Rails controller, why does an update action that calls a private guard method doing redirect_to ... and return still raise AbstractController::DoubleRenderError?

level: seniorimportance: should knowfreq 50%

basics

~20 s

The return inside the guard exits only the guard method. The action keeps running to its own redirect_to or render, which finds response_body already set and raises AbstractController::DoubleRenderError. Check performed? after the guard, or make the guard a before_action.

open as a page

In a Rails ActionController::Live action, what is ActionController::Live::ClientDisconnected, when is it raised, and how should the action handle it?

level: seniorimportance: should knowfreq 20%

basics

~20 s

ActionController::Live::ClientDisconnected is the RuntimeError that response.stream.write raises once the viewer has gone. It surfaces only on a write after the server noticed, so the action should rescue it as a normal end, send periodic heartbeats and close the stream in ensure.

open as a page

While a Rails ActionController::Live build-log stream stays open for twenty minutes, which threads and Active Record connections does it tie up?

level: seniorimportance: should knowfreq 28%

basics

~20 s

One web server thread iterating the body and one live thread running the action. The live thread checks out its own Active Record connections; a transaction or sticky lease held across sleeps pins one for the whole stream.

open as a page

In a Rails controller, what do render's template:, plain:, html:, body: and inline: options each send, and which of them use the layout?

level: juniorimportance: nice to knowfreq 25%

basics

~20 s

template: renders a view file by path inside the layout; plain: sends text/plain; html: sends text/html, escaping strings not marked html_safe; body: sends the string as is, text/plain unless content_type: says otherwise; inline: renders an ERB string. Only template renders get the layout unless layout: is passed.

open as a page

In a Rails 8.1 controller, what does wrap_parameters do with a JSON body like {"full_name": "Ada"}, and which keys does it leave out?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

For a JSON request without a job_application key, wrap_parameters copies the body's keys under job_application, so params.expect(job_application: [...]) works; with an Active Record model it copies only the model's attribute names, leaving virtual attributes out.

open as a page

showing 31–38 of 38