Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/controllers/builders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class BuildersController < ApplicationController
before_action :set_canadian_builder, only: %i[ show ]

# GET /builders
def index
@canadian_builders = CanadianBuilder.order(:name)
render json: @canadian_builders.as_json(only: [ :id, :name, :title, :location, :description, :category, :slug ])
end

# GET /builders/1
def show
end

private
# Use callbacks to share common setup or constraints between actions.
def set_canadian_builder
id = params.expect(:id)
if id.match(/[0-9]/)
@canadian_builder = CanadianBuilder.find(id)
else
@canadian_builder = CanadianBuilder.find_by(slug: id)
end
end
end

Check failure on line 24 in app/controllers/builders_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingEmptyLines: Final newline missing.
20 changes: 20 additions & 0 deletions app/models/canadian_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class CanadianBuilder < ApplicationRecord
belongs_to :government

validates :name, presence: true
validates :title, presence: true
validates :location, presence: true
validates :category, presence: true
validates :description, presence: true
validates :achievement, presence: true
validates :avatar, presence: true
validates :website, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), message: "must be a valid URL" }, allow_blank: true

before_validation :generate_slug, on: :create

private

def generate_slug
self.slug = name.parameterize if name.present?
end
end

Check failure on line 20 in app/models/canadian_builder.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingEmptyLines: Final newline missing.
5 changes: 5 additions & 0 deletions app/views/builders/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
json.(@canadian_builder, :id, :name, :title, :location, :category, :description, :achievement, :avatar, :website, :slug)

json.government do
json.(@canadian_builder.government, :id, :name)
end

Check failure on line 5 in app/views/builders/show.json.jbuilder

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingEmptyLines: Final newline missing.
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
resources :departments, only: [ :index, :show ]
resources :promises, only: [ :index, :show ]
resources :evidences, only: [ :index, :show ]
resources :builders, only: [ :index, :show ]

namespace :admin do
resources :promises, only: [ :index, :show, :update, :destroy ]
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20250630162816_create_canadian_builders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class CreateCanadianBuilders < ActiveRecord::Migration[8.0]
def change
create_table :canadian_builders do |t|
t.string :name, null: false
t.string :title, null: false
t.string :location, null: false
t.string :category, null: false
t.text :description, null: false
t.text :achievement, null: false
t.string :avatar, null: false
t.string :website
t.string :slug, null: false
t.references :government, null: false, foreign_key: true

t.timestamps
end

Check failure on line 17 in db/migrate/20250630162816_create_canadian_builders.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
add_index :canadian_builders, :slug, unique: true
add_index :canadian_builders, :category
end
end
21 changes: 20 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions db/seeds/canada.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,90 @@

require_relative 'department_promises'

puts "Seeding Canadian Builders..."

builders_data = [
{
id: 1,
name: "Ryan Reynolds",
title: "Actor & Entrepreneur",
location: "Vancouver, BC",
category: "Entertainment",
description:
"From Vancouver comedy clubs to Hollywood A-lister, Ryan built a media empire spanning film, spirits, and sports. His authentic voice and business acumen turned him into one of the most influential Canadian exports.",
achievement: "Built multiple 9-figure businesses while maintaining authentic Canadian humor",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 562 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
{
id: 2,
name: "Tobias Lütke",
title: "Founder & CEO, Shopify",
location: "Ottawa, ON",
category: "Technology",
description:
"A German immigrant who couldn't find good e-commerce software, so he built Shopify. Today, his platform powers over 4 million businesses worldwide and has created countless entrepreneurial success stories.",
achievement: "Democratized e-commerce for millions of entrepreneurs globally",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 573 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
{
id: 3,
name: "Margaret Atwood",
title: "Author & Visionary",
location: "Toronto, ON",
category: "Literature",
description:
"Her dystopian masterpiece 'The Handmaid's Tale' predicted societal challenges decades before they emerged. Margaret's work continues to shape global conversations about freedom, power, and human rights.",
achievement: "Authored works that became cultural phenomena and social movements",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 584 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
{
id: 4,
name: "Chris Hadfield",
title: "Astronaut & Inspiration Leader",
location: "Milton, ON",
category: "Science",
description:
"From small-town Ontario to commanding the International Space Station, Chris showed the world that Canadians can reach for the stars. His space videos inspired millions to pursue STEM careers.",
achievement: "First Canadian to command the International Space Station",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 595 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
{
id: 5,
name: "Céline Dion",
title: "Global Music Icon",
location: "Charlemagne, QC",
category: "Music",
description:
"From singing in her family's piano bar to selling 250+ million records worldwide, Céline proved that talent, determination, and authenticity can conquer any stage. Her voice became Canada's gift to the world.",
achievement: "One of the best-selling music artists of all time with 250M+ records sold",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 606 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
{
id: 6,
name: "David Suzuki",
title: "Environmental Pioneer",
location: "Vancouver, BC",
category: "Environment",
description:
"For over 50 years, David has been Canada's environmental conscience. His work educated generations about climate change and inspired a global movement toward sustainable living.",
achievement: "Educated millions about environmental science through 'The Nature of Things'",
avatar: "/placeholder.svg?height=120&width=120",

Check failure on line 617 in db/seeds/canada.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
},
]

builders_data.each do |attrs|
CanadianBuilder.find_or_create_by!(name: attrs[:name], government: government) do |builder|
builder.title = attrs[:title]
builder.location = attrs[:location]
builder.category = attrs[:category]
builder.description = attrs[:description]
builder.achievement = attrs[:achievement]
builder.avatar = attrs[:avatar]
builder.website = attrs[:website]
builder.slug = attrs[:name].parameterize
end
end

puts "Seeding Evidences..."

puts "Done seeding"
Loading