Social media application built with Ruby on Rails that provides comprehensive social networking features including posts, comments, likes, and user connections. The platform integrates OAuth authentication and real-time social interactions in a familiar Facebook-like interface.
A modern, full-stack social media application built with Ruby on Rails that provides comprehensive social networking features including posts, comments, likes, and user connections. The platform integrates OAuth authentication and real-time social interactions in a familiar Facebook-like interface.
odinbook/
โโโ app/ # Rails application logic
โ โโโ controllers/ # Application controllers
โ โ โโโ application_controller.rb # Base controller
โ โ โโโ posts_controller.rb # Posts CRUD operations
โ โ โโโ comments_controller.rb # Comment management
โ โ โโโ likes_controller.rb # Like/unlike functionality
โ โ โโโ follow_requests_controller.rb # Follow system
โ โ โโโ users_controller.rb # User discovery
โ โ โโโ users_profile_controller.rb # Profile management
โ โโโ models/ # Data models and business logic
โ โ โโโ user.rb # User model with Devise + OAuth
โ โ โโโ post.rb # Post model with validations
โ โ โโโ comment.rb # Comment threading system
โ โ โโโ like.rb # Like association model
โ โ โโโ follow_request.rb # Follow relationship model
โ โโโ views/ # ERB templates and partials
โ โ โโโ posts/ # Post-related views
โ โ โโโ users/ # User management views
โ โ โโโ comments/ # Comment display templates
โ โ โโโ shared/ # Reusable partial templates
โ โ โโโ layouts/ # Application layout templates
โ โโโ helpers/ # View helper methods
โ โ โโโ application_helper.rb # Global helper methods
โ โ โโโ posts_helper.rb # Post-specific helpers
โ โโโ javascript/ # Stimulus controllers and JS
โ โ โโโ application.js # Main JavaScript entry point
โ โ โโโ controllers/ # Stimulus JavaScript controllers
โ โ โโโ *.js # Feature-specific JavaScript
โ โโโ assets/ # Stylesheets and static assets
โ โโโ stylesheets/ # Sass/SCSS styling
โ โโโ images/ # Application images and icons
โโโ config/ # Rails configuration
โ โโโ routes.rb # Application routing
โ โโโ database.yml # Database configuration
โ โโโ devise.rb # Authentication configuration
โ โโโ initializers/ # App initializers
โโโ db/ # Database schema and migrations
โ โโโ migrate/ # Database migration files
โ โโโ schema.rb # Current database schema
โ โโโ seeds.rb # Sample data for development
โโโ spec/ # RSpec test suite
โโโ models/ # Model unit tests
โโโ controllers/ # Controller tests
โโโ factories/ # FactoryBot test data
โโโ rails_helper.rb # RSpec configuration
Clone the repository
git clone <repository-url>
cd odinbook
Install dependencies
# Install Ruby gems
bundle install
# Install JavaScript dependencies
yarn install
# or
npm install
Database setup
# Create and setup database
rails db:create
rails db:migrate
rails db:seed
Environment configuration
Create .env
file with OAuth credentials (optional):
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_REGION=your_aws_region
AWS_BUCKET=your_s3_bucket_name
Start the development server
# Start Rails server and asset compilation
bin/dev
# or manually start components:
rails server &
yarn build --watch &
yarn build:css --watch
Access the application
# Development
bin/dev # Start all development services
rails server # Start Rails server only
rails console # Rails console for debugging
rails db:migrate # Run pending migrations
rails db:seed # Populate database with sample data
# Asset compilation
yarn build # Build JavaScript assets
yarn build:css # Compile Sass stylesheets
yarn build --watch # Watch and rebuild JavaScript
yarn build:css --watch # Watch and rebuild CSS
# Testing
rspec # Run all tests
rspec spec/models # Run model tests only
rspec spec/controllers # Run controller tests only
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable,
:omniauthable, omniauth_providers: [:github, :google_oauth2]
has_many :posts, dependent: :destroy
has_many :comments, dependent: :destroy
has_many :likes, dependent: :destroy
has_many :follow_requests, dependent: :destroy
end
class Post < ApplicationRecord
belongs_to :user
has_many :likes, dependent: :destroy
has_many :comments, dependent: :destroy
validates :title, :body, presence: true
end
GitHub OAuth Application:
http://localhost:3000/users/auth/github/callback
.env
fileGoogle OAuth Application:
http://localhost:3000/users/auth/google_oauth2/callback
.env
fileFor production file uploads:
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1
AWS_BUCKET=your-bucket-name
The application uses RSpec with FactoryBot for comprehensive testing:
# Run all tests
rspec
# Run specific test types
rspec spec/models/user_spec.rb # User model tests
rspec spec/controllers/posts_spec.rb # Posts controller tests
rspec spec/factories/ # Verify factory data
# Run with coverage
COVERAGE=true rspec
Test Coverage Includes:
The application includes Fly.io configuration:
# Install Fly CLI and authenticate
flyctl auth login
# Deploy application
fly deploy
# Monitor deployment
fly status
fly logs
# Build Docker image
docker build -t odinbook .
# Run container locally
docker run -p 3000:3000 -e DATABASE_URL=postgresql://... odinbook
DATABASE_URL=postgresql://...
RAILS_MASTER_KEY=your_master_key
SECRET_KEY_BASE=your_secret_key_base
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
Authentication Errors:
Database Issues:
# Reset database if needed
rails db:drop db:create db:migrate db:seed
# Check database connection
rails db:version
Asset Compilation Errors:
# Clear compiled assets
rm -rf app/assets/builds/*
# Rebuild assets
yarn build && yarn build:css
# Check for JavaScript errors
rails assets:precompile
Email Configuration (Development):
tmp/letter_opener/
for email previewsconfig/environments/development.rb
git checkout -b feature/amazing-feature
git commit -m 'Add amazing social feature'
git push origin feature/amazing-feature
This project is part of The Odin Project curriculum, demonstrating modern Ruby on Rails development practices for social media applications.
Built with โค๏ธ using Ruby on Rails, Hotwire, and modern web development practices
Part of The Odin Project - Ruby on Rails curriculum