Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
245: Building a Job Board Application
When people first sit down to build a job board, they almost always start with the same mental model: "I need a User and a Job. The user posts the job, and another user applies for it." It seems intuitive. It's clean. It's also exactly how you end up with a database schema that breaks the moment a real client asks for a basic feature.
Here is why that's wrong. Imagine you've built your board and "TechCorp" signs up. They have one account, and they post ten jobs. Everything is great. Then, TechCorp grows. Now they have three different recruiters—Sarah, Mike, and Jen—who all need to manage those jobs, respond to applicants, and edit descriptions. If your Job simply belongs_to :user, you're stuck. You either have to share a single password among three people (a security nightmare) or you have to manually duplicate every job post for every recruiter. It's a mess.
Stop treating the Poster as the Company
To fix this, we have to decouple the Identity (the person logging in) from the Entity (the organization paying for the listing). In a professional Ruby on Rails application, I wouldn't associate a job with a user; I'd associate it with a Company.
By introducing a Company model, you create a pivot point. Now, a Company has many Users (the recruiters) and many Jobs. Your schema should look more like this:
# The Company is the "owner" of the listing
class Company < ApplicationRecord
has_many :users
has_many :jobs
end
# The User is just the person with the login credentials
class User < ApplicationRecord
belongs_to :company, optional: true # Optional because candidates aren't in companies
has_many :job_applications
end
# The Job belongs to the organization, not the individual
class Job < ApplicationRecord
belongs_to :company
has_many :job_applications
end
I've found that this approach saves me countless hours of refactoring. It allows you to handle "Company Profiles" (logos, website URLs, descriptions) separately from the user's personal email and password. If Sarah leaves TechCorp, you just delete her User record, and the Jobs remain safely attached to the Company.
Shifting from "Applying" to "Application Tracking"
Another spot where learners often trip up is the application process. They try to put a user_id directly on the Job model to track who applied. But a job isn't "owned" by the candidate; it's a relationship between a candidate and a posting.
You need a join model—a JobApplication. This is where the real business logic lives. It's not just a link; it's where you store the candidate's cover letter, the date they applied, and most importantly, the status of the application (e.g., "pending", "interviewing", "rejected").
class JobApplication < ApplicationRecord
belongs_to :user # The Candidate
belongs_to :job
validates :user_id, uniqueness: { scope: :job_id, message: "You have already applied for this position" }
end
Note that validation above. It's a small detail, but it prevents the "double-click" bug where a candidate accidentally applies to the same role five times in three seconds. I've seen it happen in production more times than I care to admit.
When you build the controller for this, keep your concerns separate. Your JobsController should handle searching and viewing, while a dedicated ApplicationsController should handle the act of applying. Don't try to cram the "Apply" logic into the JobsController#update action. It'll make your code rigid and difficult to test.
📋 Practical Task
Build the Company-Recruiter Authorization Logic
Now that we've decoupled the User from the Company, you need to ensure that recruiters can only edit jobs belonging to their own organization. If Sarah from TechCorp tries to edit a job posted by MegaCorp, your app should stop her.
Your Task:
- Create a
JobApplicationmodel with associations toUserandJob. - In the
JobsController, implement abefore_actioncalledensure_company_member. - This method should check if the current
User'scompany_idmatches thecompany_idof theJobbeing edited. - If they don't match, redirect the user to the root path with an alert saying "You are not authorized to manage this listing."
There are no comments for now.