Add projects
This commit is contained in:
10
app/controllers/projects_controller.rb
Normal file
10
app/controllers/projects_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class ProjectsController < ApplicationController
|
||||
|
||||
def index
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
def show
|
||||
@project = Project.find(params[:id])
|
||||
end
|
||||
end
|
||||
2
app/helpers/projects_helper.rb
Normal file
2
app/helpers/projects_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ProjectsHelper
|
||||
end
|
||||
2
app/models/project.rb
Normal file
2
app/models/project.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Project < ApplicationRecord
|
||||
end
|
||||
5
app/views/projects/index.html.erb
Normal file
5
app/views/projects/index.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Projects</h1>
|
||||
|
||||
<% @projects.each do |project| %>
|
||||
<li><%= link_to project.name, project_path(project) %></li>
|
||||
<% end %>
|
||||
2
app/views/projects/show.html.erb
Normal file
2
app/views/projects/show.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<h1><%= @project.name %></h1>
|
||||
<%= link_to "Back", projects_path %>
|
||||
@@ -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.
|
||||
|
||||
9
db/migrate/20251027095143_create_projects.rb
Normal file
9
db/migrate/20251027095143_create_projects.rb
Normal file
@@ -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
|
||||
8
db/schema.rb
generated
8
db/schema.rb
generated
@@ -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"
|
||||
|
||||
7
test/controllers/projects_controller_test.rb
Normal file
7
test/controllers/projects_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class ProjectsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/fixtures/projects.yml
vendored
Normal file
7
test/fixtures/projects.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
7
test/models/project_test.rb
Normal file
7
test/models/project_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class ProjectTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user