Added projects
This commit is contained in:
parent
0964187f22
commit
8b4ffb83ec
37 changed files with 470 additions and 1935 deletions
62
app/controllers/projects_controller.rb
Normal file
62
app/controllers/projects_controller.rb
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class ProjectsController < ApplicationController
|
||||
before_action :set_project, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /projects
|
||||
def index
|
||||
@projects = Project.all
|
||||
end
|
||||
|
||||
# GET /projects/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /projects/new
|
||||
def new
|
||||
@project = Project.new
|
||||
end
|
||||
|
||||
# GET /projects/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /projects
|
||||
def create
|
||||
@project = if params[:copy_from_id]
|
||||
Project.find(params[:copy_from_id]).dup
|
||||
else
|
||||
Project.new(project_params)
|
||||
end
|
||||
|
||||
if @project.save
|
||||
redirect_to @project, notice: "Project was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /projects/1
|
||||
def update
|
||||
if @project.update(project_params)
|
||||
redirect_to @project, notice: "Project was successfully updated.", status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /projects/1
|
||||
def destroy
|
||||
@project.destroy!
|
||||
redirect_to projects_url, notice: "Project was successfully destroyed.", status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_project
|
||||
@project = Project.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def project_params
|
||||
params.require(:project).permit(:name, :details)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue