From 32e2872bbd73431f7bf1805e195367329b316784 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 15:48:55 +0800 Subject: [PATCH] modify users controller code --- app/controllers/users_controller.rb | 27 ++++++++++----------- app/views/users/reply_message.json.jbuilder | 1 - 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 app/views/users/reply_message.json.jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17281087b..d01973175 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,10 +9,6 @@ class UsersController < ApplicationController @user = User.find params[:id] @user.update!(user_params) render_ok - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback end # 贴吧获取用户信接口 @@ -69,21 +65,24 @@ class UsersController < ApplicationController # 用户回复功能 def reply_message - @message = JournalsForMessage.new(reply_message_params) - @message.user_id = current_user.id - @message.save! - #normal_status("回复成功") + message = JournalsForMessage.new(reply_message_params) + message.user_id = current_user.id + message.save! + + render_ok(id: message.id) end # 搜索用户具有管理员角色的项目 def search_user_projects - condition = '%%' - condition = "%#{params[:search].strip}%".gsub(" ","") if !params[:search].blank? + projects = Project.where.not(status: 9) + + projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 }) + projects = projects.where(members: { user_id: current_user.id }) + + search = params[:search].to_s.strip + projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? - project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id - AND m.id=mr.member_id AND mr.role_id = 3 AND m.user_id=#{current_user.id} AND p.status != 9 and - p.name like '#{condition}'") - @projects = Project.where(id: project_ids.pluck(:id)) + @projects = projects.select(:id, :name) end # 个人主页信息 diff --git a/app/views/users/reply_message.json.jbuilder b/app/views/users/reply_message.json.jbuilder deleted file mode 100644 index 26052baa8..000000000 --- a/app/views/users/reply_message.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.id @message.id \ No newline at end of file