Project create
This commit is contained in:
@@ -8,11 +8,24 @@ class ProjectsController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@project = Project.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@project = Project.new(project_params)
|
||||||
|
if @project.save
|
||||||
|
redirect_to @project
|
||||||
|
else
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @project.update(params.expect(project: %i[code name description]))
|
if @project.update(project_params)
|
||||||
redirect_to @project
|
redirect_to @project
|
||||||
else
|
else
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
@@ -27,4 +40,8 @@ class ProjectsController < ApplicationController
|
|||||||
def fetch_project!
|
def fetch_project!
|
||||||
@project = Project.find_by!(code: params[:id])
|
@project = Project.find_by!(code: params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def project_params
|
||||||
|
params.expect(project: %i[code name description])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
validates :name, :code, presence: true
|
validates :name, :code, presence: true
|
||||||
|
validates :code, exclusion: { in: %w[new] }, uniqueness: true
|
||||||
|
|
||||||
has_many :tasks
|
has_many :tasks
|
||||||
|
|
||||||
has_rich_text :description
|
has_rich_text :description
|
||||||
|
|
||||||
|
before_validation :lowercase_code
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
return unless id
|
return unless id
|
||||||
code
|
code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def lowercase_code
|
||||||
|
return if code.blank?
|
||||||
|
|
||||||
|
self.code = self.code.downcase
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
h1 New project
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
Reference in New Issue
Block a user