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 pageshowhide
explore
- Formats & Implicit Rendering5 questions
- Strong Parameters5 questions
- Filter Chains & Halting4 questions
- Render, Redirect & Head6 questions
- Flash Messages & Session Stores4 questions
- Signed & Encrypted Cookies4 questions
- File Sends & Live Streams5 questions
- Rescue Handlers & Error Pages5 questions
questions
page 2 of 2After 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?
basics
~20 sportfolio_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.
In a Rails controller, why does an update action that calls a private guard method doing redirect_to ... and return still raise AbstractController::DoubleRenderError?
basics
~20 sThe 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.
In Rails, what happens when a cookie-store session outgrows 4 KB, and when would you switch config.session_store to :cache_store instead?
basics
~20 sRails raises ActionDispatch::Cookies::CookieOverflow when the encrypted session cookie exceeds 4096 bytes. First move bulky data into tables; switch to :cache_store when sessions must be large or revocable, accepting that cache eviction or a non-persistent cache store loses sessions.
In a Rails app on the cookie session store, what do reset_session and expire_after actually guarantee about ending a session?
basics
~20 sreset_session empties the session, issues a new session id, resets the CSRF token and clears the flash, but with the cookie store an old copy of the cookie still decrypts. expire_after both sets the cookie's expiry and embeds it, so Rails rejects older cookies after that time.
In a Rails ActionController::Live action, what is ActionController::Live::ClientDisconnected, when is it raised, and how should the action handle it?
basics
~20 sActionController::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.
While a Rails ActionController::Live build-log stream stays open for twenty minutes, which threads and Active Record connections does it tie up?
basics
~20 sOne 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.
In a Rails controller, what do render's template:, plain:, html:, body: and inline: options each send, and which of them use the layout?
basics
~20 stemplate: 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.
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?
basics
~20 sFor 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.
showing 31–38 of 38