From 6c3180f203fb81c12381a5ea206705114d136765 Mon Sep 17 00:00:00 2001 From: KaungKaung Date: Tue, 27 Jan 2026 11:43:00 +0630 Subject: [PATCH] Nested routes, Listed tasks associated with projects --- app/controllers/projects_controller.rb | 22 ++++++++++++++++++++++ app/helpers/projects_helper.rb | 2 ++ app/views/projects/index.html.erb | 7 +++++++ app/views/projects/new.html.erb | 17 +++++++++++++++++ app/views/projects/show.html.erb | 10 ++++++++++ config/routes.rb | 7 +++++++ 6 files changed, 65 insertions(+) create mode 100644 app/controllers/projects_controller.rb create mode 100644 app/helpers/projects_helper.rb create mode 100644 app/views/projects/index.html.erb create mode 100644 app/views/projects/new.html.erb create mode 100644 app/views/projects/show.html.erb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb new file mode 100644 index 0000000..1565773 --- /dev/null +++ b/app/controllers/projects_controller.rb @@ -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 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/views/projects/index.html.erb b/app/views/projects/index.html.erb new file mode 100644 index 0000000..127fe18 --- /dev/null +++ b/app/views/projects/index.html.erb @@ -0,0 +1,7 @@ +

Projects

+ + diff --git a/app/views/projects/new.html.erb b/app/views/projects/new.html.erb new file mode 100644 index 0000000..e9feebd --- /dev/null +++ b/app/views/projects/new.html.erb @@ -0,0 +1,17 @@ +

New Project

+ +<%= form_with model: @project do |form| %> +
+ <%= form.label :project_name %>
+ <%= form.text_field :project_name %> +
+ +
+ <%= form.label :description %>
+ <%= form.text_area :description %> +
+ +
+ <%= form.submit %> +
+<% end %> \ No newline at end of file diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb new file mode 100644 index 0000000..fbb2f53 --- /dev/null +++ b/app/views/projects/show.html.erb @@ -0,0 +1,10 @@ +

<%= @project.project_name %>

+

<%= @project.description %>

+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 48254e8..a656a21 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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.