From 0dc4dd623d26a4fd1810f046c03b77a09deebeb8 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Mon, 27 Oct 2025 12:18:14 +0100 Subject: [PATCH] Add projects --- app/controllers/projects_controller.rb | 10 ++++++++++ app/helpers/projects_helper.rb | 2 ++ app/models/project.rb | 2 ++ app/views/projects/index.html.erb | 5 +++++ app/views/projects/show.html.erb | 2 ++ config/routes.rb | 3 +++ db/migrate/20251027095143_create_projects.rb | 9 +++++++++ db/schema.rb | 8 +++++++- test/controllers/projects_controller_test.rb | 7 +++++++ test/fixtures/projects.yml | 7 +++++++ test/models/project_test.rb | 7 +++++++ 11 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/controllers/projects_controller.rb create mode 100644 app/helpers/projects_helper.rb create mode 100644 app/models/project.rb create mode 100644 app/views/projects/index.html.erb create mode 100644 app/views/projects/show.html.erb create mode 100644 db/migrate/20251027095143_create_projects.rb create mode 100644 test/controllers/projects_controller_test.rb create mode 100644 test/fixtures/projects.yml create mode 100644 test/models/project_test.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb new file mode 100644 index 0000000..e3235d2 --- /dev/null +++ b/app/controllers/projects_controller.rb @@ -0,0 +1,10 @@ +class ProjectsController < ApplicationController + + def index + @projects = Project.all + end + + def show + @project = Project.find(params[:id]) + end +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb new file mode 100644 index 0000000..db5c5ce --- /dev/null +++ b/app/helpers/projects_helper.rb @@ -0,0 +1,2 @@ +module ProjectsHelper +end diff --git a/app/models/project.rb b/app/models/project.rb new file mode 100644 index 0000000..9c7fe3f --- /dev/null +++ b/app/models/project.rb @@ -0,0 +1,2 @@ +class Project < ApplicationRecord +end diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb new file mode 100644 index 0000000..d1860a1 --- /dev/null +++ b/app/views/projects/index.html.erb @@ -0,0 +1,5 @@ +

Projects

+ +<% @projects.each do |project| %> +
  • <%= link_to project.name, project_path(project) %>
  • +<% end %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb new file mode 100644 index 0000000..628f33e --- /dev/null +++ b/app/views/projects/show.html.erb @@ -0,0 +1,2 @@ +

    <%= @project.name %>

    +<%= link_to "Back", projects_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 52a955c..4420d04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do resources :todos + get "/projects", to: "projects#index" + get "/projects/:id", to: "projects#show", as: "project" + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. diff --git a/db/migrate/20251027095143_create_projects.rb b/db/migrate/20251027095143_create_projects.rb new file mode 100644 index 0000000..910dfd7 --- /dev/null +++ b/db/migrate/20251027095143_create_projects.rb @@ -0,0 +1,9 @@ +class CreateProjects < ActiveRecord::Migration[8.1] + def change + create_table :projects do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 134129d..daba742 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2025_10_27_091014) do +ActiveRecord::Schema[8.1].define(version: 2025_10_27_095143) do + create_table "projects", force: :cascade do |t| + t.datetime "created_at", null: false + t.string "name" + t.datetime "updated_at", null: false + end + create_table "todos", force: :cascade do |t| t.datetime "created_at", null: false t.text "description" diff --git a/test/controllers/projects_controller_test.rb b/test/controllers/projects_controller_test.rb new file mode 100644 index 0000000..bc11e96 --- /dev/null +++ b/test/controllers/projects_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ProjectsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/projects.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/project_test.rb b/test/models/project_test.rb new file mode 100644 index 0000000..5df4ca4 --- /dev/null +++ b/test/models/project_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ProjectTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end