diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 44854cb..5a56ea4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -52,25 +52,24 @@ class ProjectsController < ApplicationController #=============================================>项目添加用户 def addUsers - #Todo - uid = params[:user_id] - register = session[:user_id] - #username = params[:username] - pid = params[:project_id] - params_pu = {project_id: pid,user_id: uid} - pu = Projects_user.new(params_pu) - pu.save - content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name - puts content - params_note = {user_id: uid,content: content,category: 2,project_id: pid} - note = Note.new(params_note) - note.save! - #puts Note.find_by(id: note.id).inspect - # now = Datetime.now - # note.created_at = now - # note.updated_at = now - note.save! - render :json => {:code => 0} + uid = User.find_by(email:params[:email]).id# 需要添加的用户 + register = session[:user_id]# 当前用户 + pid = params[:project_id] + # 检查该项目中是否已经有要添加的用户 + pu_exist=Projects_user.find_by(project_id:pid,user_id:uid) + if pu_exist.nil?# 不存在 + params_pu = {project_id: pid,user_id: uid} + pu = Projects_user.new(params_pu) + pu.save + content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name + puts content + params_note = {user_id: uid,content: content,category: 2,project_id: pid} + note = Note.new(params_note) + note.save! + render :json => {:code => 0} + else# 存在 + render json:current_user.errors, status: :unprocessable_entity + end end #=============================================>项目详情 @@ -117,6 +116,7 @@ class ProjectsController < ApplicationController render json:current_user.errors, status: :unprocessable_entity end end + private def project_params params.require(:project).permit(:name,:content,:id) diff --git a/public/pages/project_detail.html b/public/pages/project_detail.html index 15b521f..44b76d3 100644 --- a/public/pages/project_detail.html +++ b/public/pages/project_detail.html @@ -77,7 +77,7 @@
@@ -92,7 +92,6 @@ -