ambition/app/controllers/shares_controller.rb

38 lines
783 B
Ruby

class SharesController < ApplicationController
before_action :authenticate
#当前用户创建分享
def create
#Todo
body = request.body.read
put = Share.new()
put.content = body[:content]
put.project_id = body[:project_id]
put.user_id = session[:user_id]
put.save!
render :json => {:code => 0}
end
#获取项目的分享列表
def getShareList
#Todo
pid = params[:project_id]
data = []
Share.where(:project_id => pid) do |i|
name = User.find(i.user_id).name
data += [{
:nickname => name,
:time => i.created_at,
:content => i.content
}]
end
render :json => {
:code => 0,
:data => data
}
end
end