Ruby on Rails Technology & Digital Applications 3 — Questions and Answers
Question 1: In Rails, which tool is commonly used to run JavaScript and CSS bundling in a modern asset pipeline?
- Sprockets alone with CoffeeScript
- jsbundling-rails with esbuild, rollup, or webpack (Correct answer)
- Uglifier gem directly
- ActionView::AssetPipeline::JSCompressor
Correct answer: jsbundling-rails with esbuild, rollup, or webpack
Rails 7 introduced `jsbundling-rails` to integrate modern bundlers (esbuild, rollup, webpack) into the asset pipeline.
Question 2: What does the `turbo_method: :delete` option do in a Rails link helper?
- Sends a DELETE request via Turbo instead of a standard anchor GET request (Correct answer)
- Deletes the Turbo Frame cache for that link
- Triggers a full page reload with HTTP DELETE
- Removes the link element from the DOM
Correct answer: Sends a DELETE request via Turbo instead of a standard anchor GET request
Since HTML anchors only support GET, `turbo_method: :delete` makes Turbo intercept the click and send a DELETE HTTP request.
Question 3: Which Rack middleware does Rails include by default to protect against Cross-Site Request Forgery?
- Rack::Attack
- ActionDispatch::RequestForgeryProtection via ApplicationController (Correct answer)
- Rack::CSRF::Middleware
- Devise::TokenAuthenticatable
Correct answer: ActionDispatch::RequestForgeryProtection via ApplicationController
Rails includes CSRF protection via `protect_from_forgery` in ApplicationController, embedding an authenticity token in forms.
Question 4: When using Rails with a React frontend (API mode), which gem helps configure CORS headers?
- rack-rewrite
- rack-cors (Correct answer)
- actionpack-cors
- rails-cors-headers
Correct answer: rack-cors
The `rack-cors` gem adds Cross-Origin Resource Sharing headers to Rails API responses, allowing browsers to make cross-domain requests.
Question 5: How does Rails 7's importmap-rails gem differ from webpack-based asset bundling?
- It compiles TypeScript to ES5 automatically
- It uses browser-native ES module imports without a build step (Correct answer)
- It replaces the database ORM layer
- It bundles CSS alongside JavaScript
Correct answer: It uses browser-native ES module imports without a build step
Import maps let modern browsers load ES modules directly from URLs, eliminating the npm/webpack build step entirely.
Question 6: In Rails, which method on an ActiveStorage attachment generates a URL expiring after a set time?
- rails_blob_path(object.file, disposition: :attachment)
- url_for(object.file, expires_in: 1.hour) (Correct answer)
- ActiveStorage::Blob#signed_id
- object.file.service_url(expires_in: 1.hour)
Correct answer: url_for(object.file, expires_in: 1.hour)
`url_for` with `expires_in` generates a signed, time-limited URL to the ActiveStorage blob via the configured storage service.
Question 7: What is the role of `ActionCable` in a Rails application?
- To compress cable/network payloads for faster HTTP responses
- To provide WebSocket-based real-time communication channels (Correct answer)
- To manage background job queues over TCP
- To enable HTTP/2 server push for assets
Correct answer: To provide WebSocket-based real-time communication channels
Action Cable integrates WebSockets into Rails, enabling real-time features like chat, notifications, and live updates via named channels.
In Rails, which tool is commonly used to run JavaScript and CSS bundling in a modern asset pipeline?