Ruby on Rails Technology & Digital Applications 4 — Questions and Answers
Question 1: Which Rails command generates a fully resourceful JSON API controller with no views?
- rails generate scaffold_controller API::Resource --api
- rails generate controller ResourcesController --api-only
- rails generate resource Resource --skip-views
- rails generate scaffold Resource --api (Correct answer)
Correct answer: rails generate scaffold Resource --api
`rails generate scaffold Resource --api` creates model, migration, routes, and a controller rendering JSON without view templates.
Question 2: In Rails, which cache store is best suited for a multi-server production deployment?
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::RedisCacheStore or MemCacheStore (Correct answer)
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::NullStore
Correct answer: ActiveSupport::Cache::RedisCacheStore or MemCacheStore
Redis and Memcached cache stores are shared across servers, making them suitable for horizontally scaled production deployments.
Question 3: What does enabling `config.force_ssl = true` do in a Rails production environment?
- Generates a self-signed SSL certificate automatically
- Redirects all HTTP requests to HTTPS and sets HSTS headers (Correct answer)
- Encrypts the database connection string
- Forces SSL verification on outbound HTTP calls
Correct answer: Redirects all HTTP requests to HTTPS and sets HSTS headers
`force_ssl` adds the `ActionDispatch::SSL` middleware that redirects HTTP→HTTPS and adds Strict-Transport-Security headers.
Question 4: Which Sidekiq feature allows failed background jobs to be automatically retried with exponential backoff?
- Sidekiq::RetrySet with cron scheduling
- Built-in retry logic; jobs are retried up to 25 times by default with exponential delays (Correct answer)
- ActiveJob::Retry plugin separately installed
- Manually calling `perform_later` inside a rescue block
Correct answer: Built-in retry logic; jobs are retried up to 25 times by default with exponential delays
Sidekiq automatically retries failed jobs up to 25 times using exponential backoff, configurable per worker via `sidekiq_options`.
Question 5: When uploading files to S3 from a Rails app using Active Storage, what advantage does direct upload provide?
- Files are encrypted by Rails before sending to S3
- Files go directly from the browser to S3, bypassing the Rails server (Correct answer)
- Rails compresses files before forwarding them to S3
- Direct upload stores files locally first, then syncs to S3
Correct answer: Files go directly from the browser to S3, bypassing the Rails server
Direct upload lets the browser send large files straight to S3 using pre-signed URLs, reducing load on the Rails server.
Question 6: What is the purpose of `config.cache_classes = false` in the Rails development environment?
- It disables fragment caching to show live data
- It reloads application code on each request so changes take effect without restarting (Correct answer)
- It prevents ActiveRecord from caching SQL query results
- It turns off class-level memoization in models
Correct answer: It reloads application code on each request so changes take effect without restarting
With `cache_classes: false`, Rails reloads changed Ruby files on every request, enabling hot-reload during development.
Question 7: Which Rails logger configuration reduces log verbosity in production while still capturing errors?
- config.log_level = :debug
- config.log_level = :warn or :error (Correct answer)
- config.logger = ActiveSupport::NullLogger
- config.log_tags = [:uuid, :remote_ip]
Correct answer: config.log_level = :warn or :error
Setting `log_level` to `:warn` or `:error` in production suppresses informational and debug output while still logging warnings and errors.
Which Rails command generates a fully resourceful JSON API controller with no views?