Project show and edit

This commit is contained in:
2025-06-22 00:52:49 +03:00
parent ab477cb37c
commit 717e64a034
12 changed files with 80 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
class ProjectsController < ApplicationController
before_action :fetch_project!, only: %w[show edit update destroy]
def index
@projects = Project.all
end
def show
end
def edit
end
def update
if @project.update(params.expect(project: %i[code name description]))
redirect_to @project
else
render :edit, status: :unprocessable_entity
end
end
def destroy
end
private
def fetch_project!
@project = Project.find_by!(code: params[:id])
end
end
+2
View File
@@ -0,0 +1,2 @@
module ProjectsHelper
end
+3
View File
@@ -1,3 +1,6 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
import "trix"
import "@rails/actiontext"
+5
View File
@@ -4,4 +4,9 @@ class Project < ApplicationRecord
has_many :tasks
has_rich_text :description
def to_param
return unless id
code
end
end
+13
View File
@@ -0,0 +1,13 @@
= form_with model: @project do |form|
.field
= form.label :code
= form.text_field :code
.field
= form.label :name
= form.text_field :name
.field
= form.label :description
= form.rich_textarea :description
.submit
= form.submit 'Submit'
+5
View File
@@ -0,0 +1,5 @@
h1
span Editing project
span= @project.name
= render 'form'
+3
View File
@@ -0,0 +1,3 @@
ul
- @projects.each do |project|
li= link_to project.name, project
+7
View File
@@ -0,0 +1,7 @@
h1= @project.name
section= @project.description
section
ul.links
li= link_to 'Edit', edit_project_path(@project)