Ruby on Rails Technology & Digital Applications 5 — Questions and Answers
Question 1: In a Rails app, which approach lets you serve a Vue.js or React SPA while still using Rails for the API?
- Mount the SPA in config/routes.rb using mount ReactApp
- Serve the SPA separately (e.g., Vercel/Netlify) and point it at a Rails API-only app (Correct answer)
- Use ActionView with embedded Vue components via asset pipeline only
- Configure Turbolinks to intercept all React routing
Correct answer: Serve the SPA separately (e.g., Vercel/Netlify) and point it at a Rails API-only app
A decoupled architecture serves the SPA via a CDN or static host while the Rails API-only app handles data requests, enabling independent deployment.
Question 2: Which Rails helper method generates a `<meta>` CSRF token tag used by JavaScript fetch requests?
- csrf_token_tag
- csrf_meta_tags (Correct answer)
- form_authenticity_token_tag
- protect_from_forgery_tag
Correct answer: csrf_meta_tags
`csrf_meta_tags` renders `<meta name="csrf-token">` and `<meta name="csrf-param">` tags that JS can read to include the token in AJAX requests.
Question 3: What does the `jbuilder` gem enable in Rails views?
- JSON schema validation for API inputs
- A DSL for building JSON responses in `.json.jbuilder` view templates (Correct answer)
- JavaScript bundling via a Builder pattern
- JVM-based Ruby execution for JSON parsing speed
Correct answer: A DSL for building JSON responses in `.json.jbuilder` view templates
Jbuilder provides a Ruby DSL in `.json.jbuilder` templates to construct JSON responses with conditional logic and partials.
Question 4: Which Active Record method efficiently loads associated records to prevent N+1 queries in a Rails API response?
- preload, eager_load, or includes (Correct answer)
- joins only
- select with subqueries
- find_each with batch_size
Correct answer: preload, eager_load, or includes
`includes`, `preload`, and `eager_load` all solve N+1 by loading associations in separate or joined queries before iteration.
Question 5: When configuring Rails to send emails via SendGrid in production, which setting specifies the SMTP delivery method?
- config.action_mailer.delivery_method = :smtp with smtp_settings (Correct answer)
- config.action_mailer.delivery_method = :sendgrid_api
- config.mailer.transport = :sendgrid
- ActionMailer::Base.email_provider = :sendgrid
Correct answer: config.action_mailer.delivery_method = :smtp with smtp_settings
ActionMailer uses `delivery_method: :smtp` with host/port/credentials in `smtp_settings` to route mail through SendGrid's SMTP relay.
Question 6: What is the function of the `Rack::Attack` gem in a Rails application?
- It automatically patches known CVEs in Rack middleware
- It rate-limits, throttles, and blocks abusive requests at the Rack layer (Correct answer)
- It scans uploaded files for malware attachments
- It encrypts all request parameters before they reach the controller
Correct answer: It rate-limits, throttles, and blocks abusive requests at the Rack layer
Rack::Attack is middleware for rate limiting and blocking malicious IP addresses or patterns before requests hit the Rails app layer.
Question 7: In Rails 7+, which approach replaces the need for `webpacker` to compile JavaScript?
- Sprockets 4 with ES6 transpilation built-in
- importmap-rails for ESM or jsbundling-rails for bundlers like esbuild (Correct answer)
- ActionScript compiler integrated in ActiveSupport
- Turbopack adapter via the turbopack-rails gem
Correct answer: importmap-rails for ESM or jsbundling-rails for bundlers like esbuild
Rails 7 defaults to importmap-rails (no build step) or jsbundling-rails (with esbuild/rollup/webpack), both replacing the deprecated webpacker gem.
In a Rails app, which approach lets you serve a Vue.js or React SPA while still using Rails for the API?