Nested routes, Listed tasks associated with projects
This commit is contained in:
22
app/controllers/projects_controller.rb
Normal file
22
app/controllers/projects_controller.rb
Normal 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
|
||||
2
app/helpers/projects_helper.rb
Normal file
2
app/helpers/projects_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ProjectsHelper
|
||||
end
|
||||
7
app/views/projects/index.html.erb
Normal file
7
app/views/projects/index.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<h1>Projects</h1>
|
||||
|
||||
<ul>
|
||||
<% @projects.each do |project| %>
|
||||
<li><h3><%= project.project_name %></h3></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
17
app/views/projects/new.html.erb
Normal file
17
app/views/projects/new.html.erb
Normal 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 %>
|
||||
10
app/views/projects/show.html.erb
Normal file
10
app/views/projects/show.html.erb
Normal 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>
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user