0
0
Ruby on Railsframework~10 mins

Environment configuration files in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load environment variables from the .env file using dotenv gem.

Ruby on Rails
require 'dotenv'\nDotenv.[1]
Drag options to blanks, or click blank then click option'
Aread
Bload
Copen
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like read or open which do not load environment variables.
Forgetting to require the dotenv gem before calling its methods.
2fill in blank
medium

Complete the code to access the Rails environment configuration for the current environment.

Ruby on Rails
Rails.application.config_for(:[1])
Drag options to blanks, or click blank then click option'
Aenvironment
Bdatabase
Csecrets
Dcredentials
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing environment with database or secrets configuration.
Using incorrect symbols that do not match config files.
3fill in blank
hard

Fix the error in the code to correctly fetch a configuration value from credentials.

Ruby on Rails
Rails.application.credentials.[1]
Drag options to blanks, or click blank then click option'
Afetch(:api_key)
Bread(:api_key)
Cget(:api_key)
Dapi_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using fetch or get which are not valid methods on credentials.
Trying to read credentials like a hash instead of method calls.
4fill in blank
hard

Fill both blanks to define a custom configuration in config/application.rb and access it in the app.

Ruby on Rails
module MyApp\n  class Application < Rails::Application\n    config.[1] = 'value'\n  end\nend\n\nRails.application.config.[2]
Drag options to blanks, or click blank then click option'
Acustom_setting
Bcustom_value
Dcustom_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for setting and accessing the config.
Trying to access config with incorrect method names.
5fill in blank
hard

Fill all three blanks to create a YAML environment config file and load a value in Rails.

Ruby on Rails
development:\n  api_key: [1]\n\nconfig = Rails.application.config_for(:[2])\nputs config[:[3]]
Drag options to blanks, or click blank then click option'
A'123abc'
Benvironment
Capi_key
D'secret'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file name in config_for.
Accessing config keys as strings instead of symbols.
Incorrect YAML syntax for the api_key value.