A Ruby on Rails application that accepts an address as input and retrieves weather forecast data for the given location. Built with Rails best practices - thin controllers, fat models, and minimal dependencies.
- Accept address input from users
- Convert addresses to zip codes using geocoding
- Retrieve current weather data (temperature, humidity, pressure, etc.)
- Display 5-day extended forecast with high/low temperatures
- Cache weather data for 30 minutes
- Display cache indicator when data is retrieved from cache
- Modern, responsive UI design
- Error handling for invalid addresses and API failures
- Ruby 3.4.6+
- Rails 8.0.3+
- OpenWeatherMap API key (free tier available)
-
Clone the repository
git clone <your-repo-url> cd weather_forecast_app
-
Install dependencies
bundle install
-
Set up environment variables
Create a
.envfile in the root directory:OPENWEATHER_API_KEY=your_api_key_here
To get a free API key:
- Go to OpenWeatherMap
- Sign up for a free account
- Generate an API key
- Add it to your
.envfile
-
Set up the database
rails db:create rails db:migrate
-
Start the server
rails server
-
Visit the application Open your browser and go to
http://localhost:3000
- Enter a zip code in the input field (e.g., "10001", "90210")
- Also accepts full addresses (e.g., "San Francisco, CA")
- Click "Get Weather" to retrieve current weather and 5-day forecast
- The application will:
- Convert the address to a zip code (if needed)
- Fetch weather data from OpenWeatherMap API
- Display current temperature, conditions, and extended forecast
- Cache the results for 30 minutes
- Show a cache indicator if data is retrieved from cache
Built following Rails conventions:
- Thin Controllers: Controllers only handle HTTP concerns
- Fat Models: All business logic lives in the
Forecastmodel - No Comments: Code is self-documenting (except where complexity requires explanation)
- Standard Library: Uses
Net::HTTPinstead of external HTTP gems
app/
├── controllers/
│ └── forecasts_controller.rb # Thin controller - orchestration only
├── models/
│ └── forecast.rb # Fat model - all business logic
├── views/
│ └── forecasts/
│ └── index.html.erb # Main view
└── assets/
└── stylesheets/
└── application.css # Custom CSS
- OpenWeatherMap API for weather data
- Geocoder gem for address-to-zip-code conversion
- Net::HTTP for API requests (built-in Ruby library)
- Weather data cached for 30 minutes using Rails.cache
- Cache keys based on zip code
- Cache status displayed to users
- Subsequent requests for the same location within 30 minutes use cached data
- Framework: Ruby on Rails 8.0.3
- Database: SQLite3 (development)
- Caching: Solid Cache (Rails 8 default)
- Styling: Custom CSS with responsive design
- API: OpenWeatherMap (free tier)
The application handles:
- Invalid or non-existent addresses
- API failures or rate limits
- Network connectivity issues
- Missing API keys
- Extended 5-day forecast with high/low temperatures
- Modern, responsive UI design
- Detailed weather information (humidity, pressure, feels-like temperature)
- Location information display
- Comprehensive error handling
- Mobile-responsive design
This project is created for assessment purposes.