Bird
Raised Fist0
Ruby on Railsframework~20 mins

Production environment configuration in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Rails Production Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
1:30remaining
What is the effect of setting config.cache_classes = true in production?
In a Rails production environment configuration, what does setting config.cache_classes = true do?
AIt reloads application classes on every request, slowing down response time.
BIt enables verbose logging of class loading for debugging purposes.
CIt caches application classes so they are loaded once, improving performance.
DIt disables class loading entirely, causing errors when classes are referenced.
Attempts:
2 left
💡 Hint
Think about how caching classes affects speed and memory in production.
📝 Syntax
intermediate
1:30remaining
Identify the correct syntax to enable serving static files in production
Which of the following lines correctly enables serving static files in a Rails production environment configuration file?
Aconfig.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Bconfig.public_file_server.enabled == true
Cconfig.public_file_server.enabled = true if ENV['RAILS_SERVE_STATIC_FILES']
Dconfig.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES']
Attempts:
2 left
💡 Hint
Check how to properly assign a boolean based on environment variable presence.
❓ state_output
advanced
1:30remaining
What is the value of config.log_level after this production config runs?
Given this snippet in config/environments/production.rb:
Rails.application.configure do
  config.log_level = :info
  config.log_level = :debug if ENV['DEBUG_LOG'] == 'true'
end
If the environment variable DEBUG_LOG is not set, what is the final value of config.log_level?
A:debug
B:info
Cnil
DRaises an error because ENV['DEBUG_LOG'] is nil
Attempts:
2 left
💡 Hint
Consider what happens when the environment variable is missing.
🔧 Debug
advanced
2:00remaining
Why does this production config cause an error?
Examine this production environment configuration snippet:
Rails.application.configure do
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: 'smtp.example.com',
    port: 587,
    domain: 'example.com',
    user_name: ENV['SMTP_USER'],
    password: ENV['SMTP_PASS'],
    authentication: 'plain',
    enable_starttls_auto: true
  }
end
Why does this code raise a syntax error?
AMissing commas between some hash key-value pairs cause a syntax error.
BUsing symbols as keys in smtp_settings is not allowed in production config.
CThe delivery_method :smtp is invalid in production environment.
DENV variables cannot be used directly in production config files.
Attempts:
2 left
💡 Hint
Look carefully at punctuation between hash entries.
🧠 Conceptual
expert
2:30remaining
Which production config setting ensures assets are precompiled and digest filenames are used?
In Rails production configuration, which setting ensures that assets are precompiled and served with digest fingerprints for caching?
Aconfig.assets.precompile = false
Bconfig.assets.compile = true
Cconfig.assets.debug = true
Dconfig.assets.digest = true
Attempts:
2 left
💡 Hint
Think about how Rails manages asset filenames for caching in production.

Practice

(1/5)
1. What is the main purpose of the production.rb file in a Rails application?
easy
A. To define routes for the application
B. To enable detailed error messages for debugging
C. To configure settings that optimize the app for real users, like caching and security
D. To set up the database schema

Solution

  1. Step 1: Understand the role of production.rb

    This file holds configuration settings specifically for the production environment, where the app serves real users.
  2. Step 2: Identify key production settings

    It disables detailed error messages and enables caching to improve speed and security.
  3. Final Answer:

    To configure settings that optimize the app for real users, like caching and security -> Option C
  4. Quick Check:

    Production config = optimize for real users [OK]
Hint: Production config = speed + security settings [OK]
Common Mistakes:
  • Confusing production with development environment
  • Thinking production shows detailed errors
  • Mixing routing or database setup with production config
2. Which line correctly disables full error reports in config/environments/production.rb?
easy
A. config.consider_all_requests_local = false
B. config.show_detailed_errors = true
C. config.consider_all_requests_local = true
D. config.show_detailed_errors = false

Solution

  1. Step 1: Identify the setting for error reports

    The setting consider_all_requests_local controls whether detailed error pages show.
  2. Step 2: Know production default

    In production, this is set to false to hide detailed errors from users.
  3. Final Answer:

    config.consider_all_requests_local = false -> Option A
  4. Quick Check:

    Disable detailed errors = false [OK]
Hint: False hides errors in production [OK]
Common Mistakes:
  • Setting it to true shows errors in production
  • Using wrong config key like show_detailed_errors
  • Confusing development and production defaults
3. Given this snippet in production.rb:
config.cache_classes = true
config.action_controller.perform_caching = true
config.assets.compile = false
What happens if you deploy without precompiling assets?
medium
A. The app will crash with a syntax error
B. Rails will compile assets on the fly, slowing down requests
C. Assets will be served normally from the public folder
D. Assets will not be served, causing missing styles and scripts

Solution

  1. Step 1: Understand config.assets.compile = false

    This setting disables on-the-fly asset compilation in production.
  2. Step 2: Consequence of no precompiled assets

    If assets are not precompiled, Rails cannot serve them, so styles and scripts will be missing.
  3. Final Answer:

    Assets will not be served, causing missing styles and scripts -> Option D
  4. Quick Check:

    No precompile + compile false = missing assets [OK]
Hint: No precompile + compile false = missing assets [OK]
Common Mistakes:
  • Assuming Rails compiles assets automatically in production
  • Thinking assets serve normally without precompile
  • Confusing compile false with true
4. You see this error in production: ActionController::RoutingError (No route matches [GET] "/assets/application.css"). Which fix is correct?
medium
A. Precompile assets before deploying and keep config.assets.compile = false
B. Set config.assets.compile = true in production.rb
C. Remove caching settings from production.rb
D. Set config.consider_all_requests_local = true

Solution

  1. Step 1: Understand the error cause

    The error means the CSS asset is missing in production, likely because assets were not precompiled.
  2. Step 2: Correct fix for missing assets

    Best practice is to precompile assets before deployment and keep config.assets.compile = false for performance.
  3. Final Answer:

    Precompile assets before deploying and keep config.assets.compile = false -> Option A
  4. Quick Check:

    Missing assets fix = precompile + compile false [OK]
Hint: Always precompile assets for production [OK]
Common Mistakes:
  • Setting compile true causes slow requests
  • Removing caching does not fix missing assets
  • Enabling detailed errors leaks info in production
5. You want to securely configure your Rails app for production to use environment variables for secrets and enable caching. Which combination in production.rb is best practice?
hard
A.
config.cache_classes = false
config.action_controller.perform_caching = false
config.secret_key_base = ENV['SECRET_KEY_BASE']
B.
config.cache_classes = true
config.action_controller.perform_caching = true
config.secret_key_base = ENV['SECRET_KEY_BASE']
C.
config.cache_classes = true
config.action_controller.perform_caching = false
config.secret_key_base = 'hardcoded_secret'
D.
config.cache_classes = false
config.action_controller.perform_caching = true
config.secret_key_base = 'hardcoded_secret'

Solution

  1. Step 1: Identify caching and class loading best practices

    In production, cache_classes and perform_caching should be true for speed and efficiency.
  2. Step 2: Use environment variables for secrets

    Secrets like secret_key_base must come from environment variables, not hardcoded strings, for security.
  3. Final Answer:

    config.cache_classes = true config.action_controller.perform_caching = true config.secret_key_base = ENV['SECRET_KEY_BASE'] -> Option B
  4. Quick Check:

    Caching true + env secrets = secure production [OK]
Hint: Cache true + env secrets = secure production [OK]
Common Mistakes:
  • Disabling caching in production
  • Hardcoding secret keys in code
  • Setting cache_classes false reduces performance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard