Ruby on Rails Technology & Digital Applications 2 — Questions and Answers
Question 1: Which Rails API endpoint format is recommended for building a JSON API consumed by a React frontend?
- XML with SOAP envelope
- JSON:API specification with ActiveModel::Serializer or jsonapi-serializer (Correct answer)
- GraphQL only via apollo-server gem
- CSV streaming via ActionController::Live
Correct answer: JSON:API specification with ActiveModel::Serializer or jsonapi-serializer
Rails commonly uses JSON:API spec with serializers like jsonapi-serializer to provide structured, consistent JSON responses for frontend clients.
Question 2: When integrating Stripe payments in a Rails app, which gem is the standard Ruby client?
- pay
- stripe (Correct answer)
- braintree-rails
- active_merchant
Correct answer: stripe
The `stripe` gem is Stripe's official Ruby library used directly in Rails apps for payment processing.
Question 3: In a Rails 7 app using Hotwire, which component handles partial page updates without a full page reload?
- Stimulus controllers only
- Turbo Frames and Turbo Streams (Correct answer)
- jQuery AJAX calls
- ActionCable WebSockets only
Correct answer: Turbo Frames and Turbo Streams
Turbo Frames enable scoped partial updates and Turbo Streams push real-time changes, both part of Rails 7's Hotwire stack.
Question 4: Which Rails concern is used to add file attachment functionality to ActiveRecord models?
- Paperclip::Attachment
- ActiveStorage::Attachment via has_one_attached or has_many_attached (Correct answer)
- CarrierWave::Mount
- Dragonfly::Model::Attachment
Correct answer: ActiveStorage::Attachment via has_one_attached or has_many_attached
Active Storage ships with Rails and uses `has_one_attached` / `has_many_attached` macros to associate files with models.
Question 5: How does Rails handle background job processing for sending emails asynchronously?
- Via ActionMailer::deliver_now! method only
- Via ActionMailer#deliver_later which enqueues an ActiveJob (Correct answer)
- Via Rake tasks triggered by cron
- Via Thread.new blocks inside controllers
Correct answer: Via ActionMailer#deliver_later which enqueues an ActiveJob
`deliver_later` queues the email as an ActiveJob, allowing adapters like Sidekiq or Resque to process it outside the request cycle.
Question 6: What is the purpose of the `credentials.yml.enc` file introduced in Rails 5.2?
- To store database migrations history
- To securely store API keys and secrets encrypted with a master key (Correct answer)
- To configure environment-specific server settings
- To define SSL certificate paths
Correct answer: To securely store API keys and secrets encrypted with a master key
Rails credentials encrypt sensitive config values (API keys, secrets) in `credentials.yml.enc`, decrypted at runtime using `master.key`.
Question 7: Which Rails feature allows you to stream large CSV exports without loading all records into memory?
- ActionController::Live with response.stream (Correct answer)
- ActiveRecord::Base.export_csv!
- render csv: @records, streaming: true
- Rack::Chunked middleware only
Correct answer: ActionController::Live with response.stream
`ActionController::Live` lets controllers write to `response.stream` incrementally, enabling large file exports without full memory load.
Which Rails API endpoint format is recommended for building a JSON API consumed by a React frontend?