0
0
Ruby on Railsframework~30 mins

Environment configuration files in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Environment Configuration Files in Rails
📖 Scenario: You are building a Rails web application that needs to behave differently in development and production. For example, you want to set a custom greeting message that changes based on the environment.
🎯 Goal: Create environment configuration files in a Rails app to store a greeting message. Then, access this message in the application code to display the correct greeting depending on the environment.
📋 What You'll Learn
Create a configuration file for the development environment with a greeting message
Create a configuration file for the production environment with a different greeting message
Add a configuration variable to access the greeting message
Use the configuration variable in a Rails controller to display the greeting
💡 Why This Matters
🌍 Real World
Rails apps often need different settings for development, testing, and production environments to behave correctly and securely.
💼 Career
Understanding environment configuration is essential for Rails developers to manage app behavior and deployment safely and efficiently.
Progress0 / 4 steps
1
Create development environment configuration file
Create a file named config/environments/development.rb and add a line to set config.greeting = 'Hello from Development!' inside the Rails.application.configure do ... end block.
Ruby on Rails
Need a hint?

Remember to put the greeting inside the Rails.application.configure do ... end block.

2
Create production environment configuration file
Create a file named config/environments/production.rb and add a line to set config.greeting = 'Welcome to Production!' inside the Rails.application.configure do ... end block.
Ruby on Rails
Need a hint?

Use the same structure as development.rb but with the production greeting.

3
Add configuration access in application controller
In app/controllers/application_controller.rb, add a method named greeting_message that returns Rails.configuration.greeting.
Ruby on Rails
Need a hint?

Define a method that returns the greeting from Rails.configuration.

4
Use greeting message in a view
In app/views/layouts/application.html.erb, add a line inside the <body> tag to display the greeting message by calling greeting_message.
Ruby on Rails
Need a hint?

Use ERB tags to call the greeting_message method inside the body.