diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b324444..44854cb 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,7 +1,7 @@ class ProjectsController < ApplicationController before_action :authenticate - skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail] + skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail,:update] #=============================================>获取我的项目列表,user_id保存在session中. def index @@ -107,8 +107,18 @@ class ProjectsController < ApplicationController } } end + + #=============================================>项目修改 + def update + project = Project.find_by(:id => params[:project][:id]) + if project.update(project_params) + render :json => {:code => 0} + else + render json:current_user.errors, status: :unprocessable_entity + end + end private def project_params - params.require(:project).permit(:name,:content) + params.require(:project).permit(:name,:content,:id) end end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 74f7f30..24e0dc1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,12 +1,7 @@ class Project < ActiveRecord::Base has_and_belongs_to_many :users -<<<<<<< HEAD - validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户 - -======= validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户 ->>>>>>> 27ebee595014926419b6ccba922ad39450b73f6b validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true private diff --git a/config/routes.rb b/config/routes.rb index 0c11c60..740ee37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,7 @@ Rails.application.routes.draw do get 'projects' => 'projects#index' post 'projects' => 'projects#create' + patch 'projects' => 'projects#update' post 'projects/users' => 'projects#addUsers' get 'projects/detail' => 'projects#detail' diff --git a/public/index.html b/public/index.html index 070f9bd..a1e7f1a 100644 --- a/public/index.html +++ b/public/index.html @@ -37,7 +37,7 @@ //3:通知 //4:修改个人信息 //5:项目详情 edited by cy - var src_array=["project_select","task","share","inform","alter_info","project_detail"]; + var src_array=["project_select","task","share","inform","user_detail","project_detail"]; var src="pages/"+src_array[seq]+".html"; if(seq == 5){ $("#cy_close").click(); diff --git a/public/pages/project_detail.html b/public/pages/project_detail.html index 09d598b..15b521f 100644 --- a/public/pages/project_detail.html +++ b/public/pages/project_detail.html @@ -62,14 +62,14 @@