From 498a52d65d65077ff32693a0eeaab0fbaf2cb43f Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Mon, 2 Jan 2017 05:26:57 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=88=9B=E5=BB=BA=E5=92=8C?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=9B=E5=88=86=E4=BA=AB=E7=9A=84=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shares_controller.rb | 50 +++--- app/controllers/users_controller.rb | 7 +- config/routes.rb | 2 +- public/pages/share.html | 253 ++++++++------------------- 4 files changed, 103 insertions(+), 209 deletions(-) diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index 7af353c..aa9e2fa 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -1,33 +1,30 @@ class SharesController < ApplicationController before_action :authenticate - + skip_before_action :verify_authenticity_token, :only => [ + :create, + :getShareList + ] #当前用户创建分享 def create - #Todo uid = session[:user_id].to_i - pid = params[:project_id].to_i - now = Datetime.now - put = Share.new() - put.content = params[:content] - put.project_id = pid - put.user_id = uid - put.created_at = now - put.updated_at = now - put.save! - content = User.find(uid).name + "分享了一些事" - Project_user.where(:project_id => pid).each do |tuid| - note = Note.new - note.user_id = tuid - note.project_id = pid - note.category = 1 - note.content = content - note.created_at = now - note.updated_at = now - note.save! + share=Share.new(share_params) + share.user_id=uid + if share.save + content = User.find(uid).name + "分享了一些事" + pid=share.project_id + + Projects_user.where(:project_id => pid).each do |i| + params_note = {user_id: i.user_id,content: content,category: 1,project_id: pid} + note = Note.new(params_note) + note.save! + end + render status: :created, nothing: true + else + render json: project.errors, status: :unprocessable_entity end - render :json => {:code => 0} + end #获取项目的分享列表 @@ -36,10 +33,11 @@ class SharesController < ApplicationController #Todo pid = params[:project_id] data = [] - Share.where(:project_id => pid) do |i| + Share.where(:project_id => pid).order("created_at desc").each do |i| + puts i.content name = User.find(i.user_id).name data += [{ - :nickname => name, + :name => name, :time => i.created_at, :content => i.content }] @@ -50,4 +48,8 @@ class SharesController < ApplicationController } end + private + def share_params + params.require(:share).permit(:project_id,:content) + end end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 15b80b5..1b94e0e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,12 @@ class UsersController < ApplicationController before_action :authenticate, except: [ :emailExist, :usernameExist, :create ] - skip_before_action :verify_authenticity_token, :only => [:emailExist,:usernameExist,:create,:update] + skip_before_action :verify_authenticity_token, :only => [ + :emailExist, + :usernameExist, + :create, + :update + ] def emailExist if checkExist?(:email, params[:email]) diff --git a/config/routes.rb b/config/routes.rb index e7be66c..874fe08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,7 +64,7 @@ Rails.application.routes.draw do get 'session' => 'sessions#show' post 'shares' => 'shares#create' - get 'shares' => 'share#getShareList' + get 'shares' => 'shares#getShareList' get 'projects' => 'projects#index' post 'projects' => 'projects#create' diff --git a/public/pages/share.html b/public/pages/share.html index cdf4346..608b127 100644 --- a/public/pages/share.html +++ b/public/pages/share.html @@ -43,203 +43,29 @@
-
+

添加分享

- -
- +
-
-
-
-
-
- user image - 杨诏 - 向大家分享 - 7:30 PM 今日 -
- -
- -
- -

这几天心里颇不宁静。今晚在院子里坐着乘凉,忽然想起日日走过的荷塘,在这满月的光里,总该另有一番样子吧。月亮渐渐地升高了, 墙外马路上孩子们的欢笑,已经听不见了;妻在屋里拍着闰儿,迷迷糊糊地哼着眠歌。我悄悄地披了大衫,带上门出去。 -

-

沿着荷塘,是一条曲折的小煤屑路。这是一条幽僻的路;白天也少人走,夜晚更加寂寞。荷塘四面,长着许多树,蓊蓊郁郁的。路的一旁 ,是些杨柳,和一些不知道名字的树。没有月光的晚上,这路上阴森森的,有些怕人。今晚却很好,虽然月光也还是淡淡的。 -

-

路上只我一个人,背着手着。这一片天地好像是我的;我也像超出了平常的自己,到了另一个世界里。我爱热闹,也爱冷静;爱群居, 也爱独处。像今晚上,一个人在这苍茫的月下,什么都可以想,什么都可以不想,便觉是个自由的人。白天里一定要做的事,一定要说的话, - 现 在都可不理。这是独处的妙处,我且受用这无边的荷香月色好了。

- - - - 45 赞 - 2 评论 -
- - - - - -
-
- -
-
-
-
- user image - 杨诏 - 向大家分享 - 7:30 PM 今日 -
- -
- -
- -

这几天心里颇不宁静。今晚在院子里坐着乘凉,忽然想起日日走过的荷塘,在这满月的光里,总该另有一番样子吧。月亮渐渐地升高了, 墙外马路上孩子们的欢笑,已经听不见了;妻在屋里拍着闰儿,迷迷糊糊地哼着眠歌。我悄悄地披了大衫,带上门出去。 -

-

沿着荷塘,是一条曲折的小煤屑路。这是一条幽僻的路;白天也少人走,夜晚更加寂寞。荷塘四面,长着许多树,蓊蓊郁郁的。路的一旁 ,是些杨柳,和一些不知道名字的树。没有月光的晚上,这路上阴森森的,有些怕人。今晚却很好,虽然月光也还是淡淡的。 -

-

路上只我一个人,背着手着。这一片天地好像是我的;我也像超出了平常的自己,到了另一个世界里。我爱热闹,也爱冷静;爱群居, 也爱独处。像今晚上,一个人在这苍茫的月下,什么都可以想,什么都可以不想,便觉是个自由的人。白天里一定要做的事,一定要说的话, - 现 在都可不理。这是独处的妙处,我且受用这无边的荷香月色好了。

- - - - 45 赞 - 2 评论 -
- - - - - -
-
- -
- -
- -
@@ -259,26 +85,87 @@ - -