|
1 | 1 | class ProjectsController < ApplicationController
|
2 |
| - before_action :authenticate_user! |
3 |
| - def index |
4 |
| - end |
| 2 | + before_action :authenticate_user! |
| 3 | + before_action :set_project, only: [:show, :edit, :update, :destroy] |
5 | 4 |
|
6 |
| - def show |
7 |
| - end |
| 5 | + # GET /projects |
| 6 | + # GET /projects.json |
| 7 | + def index |
| 8 | + @projects = Project.all |
| 9 | + end |
8 | 10 |
|
9 |
| - def new |
10 |
| - end |
| 11 | + # GET /projects/1 |
| 12 | + # GET /projects/1.json |
| 13 | + def show |
| 14 | + end |
11 | 15 |
|
12 |
| - def create |
13 |
| - end |
| 16 | + # GET /projects/new |
| 17 | + def new |
| 18 | + @project = Project.new |
| 19 | + end |
14 | 20 |
|
15 |
| - def edit |
| 21 | + # GET /projects/1/edit |
| 22 | + def edit |
| 23 | + end |
| 24 | + |
| 25 | + # POST /projects |
| 26 | + # POST /projects.json |
| 27 | + def create |
| 28 | + @project = Project.new(project_params) |
| 29 | + |
| 30 | + respond_to do |format| |
| 31 | + if @project.save |
| 32 | + format.html { redirect_to @project, notice: 'Project was successfully created.' } |
| 33 | + format.json { render :show, status: :created, location: @project } |
| 34 | + else |
| 35 | + format.html { render :new } |
| 36 | + format.json { render json: @project.errors, status: :unprocessable_entity } |
| 37 | + end |
16 | 38 | end
|
| 39 | + end |
17 | 40 |
|
18 |
| - def update |
| 41 | + # PATCH/PUT /projects/1 |
| 42 | + # PATCH/PUT /projects/1.json |
| 43 | + def update |
| 44 | + respond_to do |format| |
| 45 | + if @project.update(project_params) |
| 46 | + format.html { redirect_to @project, notice: 'Project was successfully updated.' } |
| 47 | + format.json { render :show, status: :ok, location: @project } |
| 48 | + else |
| 49 | + format.html { render :edit } |
| 50 | + format.json { render json: @project.errors, status: :unprocessable_entity } |
| 51 | + end |
19 | 52 | end
|
| 53 | + end |
20 | 54 |
|
21 |
| - def destroy |
| 55 | + # DELETE /projects/1 |
| 56 | + # DELETE /projects/1.json |
| 57 | + def destroy |
| 58 | + @project.destroy |
| 59 | + respond_to do |format| |
| 60 | + format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' } |
| 61 | + format.json { head :no_content } |
22 | 62 | end
|
| 63 | + end |
23 | 64 |
|
24 |
| - private |
| 65 | + private |
| 66 | + # Use callbacks to share common setup or constraints between actions. |
| 67 | + def set_project |
| 68 | + @project = Project.find(params[:id]) |
| 69 | + end |
25 | 70 |
|
| 71 | + # Never trust parameters from the scary internet, only allow the white list through. |
26 | 72 | def project_params
|
27 |
| - params.require(:projecs).permit(:name, :description, :contact_person_details) |
| 73 | + params.require(:project).permit(:name, :description, :contact_person_details, :user_id) |
28 | 74 | end
|
29 | 75 | end
|
0 commit comments