Nested routes, Listed tasks associated with projects

This commit is contained in:
KaungKaung
2026-01-27 11:43:00 +06:30
parent fd0a6fb408
commit 6c3180f203
6 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
class ProjectsController < ApplicationController
def index
@projects = Project.all
end
def show
@project = Project.find(params[:id])
end
def new
@project = Project.new
end
def create
@project = Project.new(project_params)
if @project.save
redirect_to @project
else
render :new
end
end
end

View File

@@ -0,0 +1,2 @@
module ProjectsHelper
end

View File

@@ -0,0 +1,7 @@
<h1>Projects</h1>
<ul>
<% @projects.each do |project| %>
<li><h3><%= project.project_name %></h3></li>
<% end %>
</ul>

View File

@@ -0,0 +1,17 @@
<h1>New Project</h1>
<%= form_with model: @project do |form| %>
<div>
<%= form.label :project_name %><br>
<%= form.text_field :project_name %>
</div>
<div>
<%= form.label :description %><br>
<%= form.text_area :description %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,10 @@
<h1><%= @project.project_name %></h1>
<p><%= @project.description %></p>
<ul>
<% @project.tasks.each do |task| %>
<li>
<%= task.title %> (<%= task.status %>)
</li>
<% end %>
</ul>

View File

@@ -1,4 +1,11 @@
Rails.application.routes.draw do
root "projects#index"
resources :projects
# 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.