diff --git a/.idea/.generators b/.idea/.generators
new file mode 100644
index 0000000..1618976
--- /dev/null
+++ b/.idea/.generators
@@ -0,0 +1,8 @@
+
+
diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks
new file mode 100644
index 0000000..36e25b9
--- /dev/null
+++ b/.idea/.rakeTasks
@@ -0,0 +1,7 @@
+
+
diff --git a/.idea/guoren.iml b/.idea/guoren.iml
new file mode 100644
index 0000000..a421df4
--- /dev/null
+++ b/.idea/guoren.iml
@@ -0,0 +1,192 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..3803ed9
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..703f630
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..47e4f24
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,330 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1482408182630
+
+
+ 1482408182630
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 632a807..67af890 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,11 +1,9 @@
source 'https://rubygems.org'
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
-gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
@@ -32,6 +30,7 @@ gem 'bcrypt', '~> 3.1.7'
# gem 'capistrano-rails', group: :development
group :development, :test do
+ gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
@@ -45,5 +44,9 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end
+# group :production do
+# gem 'pg','~> 0.18.4'
+# end
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
diff --git a/Gemfile.lock b/Gemfile.lock
index fa92050..92c9ada 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -173,4 +173,4 @@ DEPENDENCIES
web-console
BUNDLED WITH
- 1.12.5
+ 1.13.6
diff --git a/Gemfile.lock.bak b/Gemfile.lock.bak
new file mode 100644
index 0000000..dc72978
--- /dev/null
+++ b/Gemfile.lock.bak
@@ -0,0 +1,178 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actioncable (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ nio4r (~> 1.2)
+ websocket-driver (~> 0.6.1)
+ actionmailer (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ actionview (= 5.0.0.1)
+ activejob (= 5.0.0.1)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 2.0)
+ actionpack (5.0.0.1)
+ actionview (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ rack (~> 2.0)
+ rack-test (~> 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ actionview (5.0.0.1)
+ activesupport (= 5.0.0.1)
+ builder (~> 3.1)
+ erubis (~> 2.7.0)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ activejob (5.0.0.1)
+ activesupport (= 5.0.0.1)
+ globalid (>= 0.3.6)
+ activemodel (5.0.0.1)
+ activesupport (= 5.0.0.1)
+ activerecord (5.0.0.1)
+ activemodel (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ arel (~> 7.0)
+ activesupport (5.0.0.1)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ arel (7.1.4)
+ bcrypt (3.1.11)
+ builder (3.2.2)
+ byebug (9.0.6)
+ coffee-rails (4.2.1)
+ coffee-script (>= 2.2.0)
+ railties (>= 4.0.0, < 5.2.x)
+ coffee-script (2.4.1)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.11.1)
+ concurrent-ruby (1.0.2)
+ debug_inspector (0.0.2)
+ erubis (2.7.0)
+ execjs (2.7.0)
+ ffi (1.9.14)
+ globalid (0.3.7)
+ activesupport (>= 4.1.0)
+ i18n (0.7.0)
+ jbuilder (2.6.0)
+ activesupport (>= 3.0.0, < 5.1)
+ multi_json (~> 1.2)
+ jquery-rails (4.2.1)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
+ listen (3.0.8)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ loofah (2.0.3)
+ nokogiri (>= 1.5.9)
+ mail (2.6.4)
+ mime-types (>= 1.16, < 4)
+ method_source (0.8.2)
+ mime-types (3.1)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2016.0521)
+ mini_portile2 (2.1.0)
+ minitest (5.9.1)
+ multi_json (1.12.1)
+ nio4r (1.2.1)
+ nokogiri (1.6.8.1)
+ mini_portile2 (~> 2.1.0)
+ pg (0.18.4)
+ puma (3.6.2)
+ rack (2.0.1)
+ rack-test (0.6.3)
+ rack (>= 1.0)
+ rails (5.0.0.1)
+ actioncable (= 5.0.0.1)
+ actionmailer (= 5.0.0.1)
+ actionpack (= 5.0.0.1)
+ actionview (= 5.0.0.1)
+ activejob (= 5.0.0.1)
+ activemodel (= 5.0.0.1)
+ activerecord (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 5.0.0.1)
+ sprockets-rails (>= 2.0.0)
+ rails-dom-testing (2.0.1)
+ activesupport (>= 4.2.0, < 6.0)
+ nokogiri (~> 1.6.0)
+ rails-html-sanitizer (1.0.3)
+ loofah (~> 2.0)
+ railties (5.0.0.1)
+ actionpack (= 5.0.0.1)
+ activesupport (= 5.0.0.1)
+ method_source
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (11.3.0)
+ rb-fsevent (0.9.8)
+ rb-inotify (0.9.7)
+ ffi (>= 0.5.0)
+ sass (3.4.22)
+ sass-rails (5.0.6)
+ railties (>= 4.0.0, < 6)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (>= 1.1, < 3)
+ spring (2.0.0)
+ activesupport (>= 4.2)
+ spring-watcher-listen (2.0.1)
+ listen (>= 2.7, < 4.0)
+ spring (>= 1.2, < 3.0)
+ sprockets (3.7.0)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.2.0)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ sqlite3 (1.3.12)
+ thor (0.19.1)
+ thread_safe (0.3.5)
+ tilt (2.0.5)
+ turbolinks (5.0.1)
+ turbolinks-source (~> 5)
+ turbolinks-source (5.0.0)
+ tzinfo (1.2.2)
+ thread_safe (~> 0.1)
+ uglifier (3.0.3)
+ execjs (>= 0.3.0, < 3)
+ web-console (3.4.0)
+ actionview (>= 5.0)
+ activemodel (>= 5.0)
+ debug_inspector
+ railties (>= 5.0)
+ websocket-driver (0.6.4)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bcrypt (~> 3.1.7)
+ byebug
+ coffee-rails (~> 4.2)
+ jbuilder (~> 2.5)
+ jquery-rails
+ listen (~> 3.0.5)
+ pg (~> 0.18.4)
+ puma (~> 3.0)
+ rails (~> 5.0.0, >= 5.0.0.1)
+ sass-rails (~> 5.0)
+ spring
+ spring-watcher-listen (~> 2.0.0)
+ sqlite3
+ turbolinks (~> 5)
+ tzinfo-data
+ uglifier (>= 1.3.0)
+ web-console
+
+BUNDLED WITH
+ 1.13.6
diff --git a/app/assets/javascripts/comments.coffee b/app/assets/javascripts/comments.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/comments.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/micro_posts.coffee b/app/assets/javascripts/micro_posts.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/micro_posts.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss
new file mode 100644
index 0000000..e730912
--- /dev/null
+++ b/app/assets/stylesheets/comments.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/micro_posts.scss b/app/assets/stylesheets/micro_posts.scss
new file mode 100644
index 0000000..1f42afc
--- /dev/null
+++ b/app/assets/stylesheets/micro_posts.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the MicroPosts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index eb0e095..694d6f9 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include LoginHelper
include UsersHelper
+ include MicroPostsHelper
# Confirms a logged-in user.
diff --git a/app/controllers/chat_controller.rb b/app/controllers/chat_controller.rb
index f56095c..923e8c3 100644
--- a/app/controllers/chat_controller.rb
+++ b/app/controllers/chat_controller.rb
@@ -9,68 +9,89 @@ class ChatController < ApplicationController
@chat_with_users = get_chat_with_users(@user)
if !@current_chat_user_name.nil?
@current_chat_user = User.find_by(name: @current_chat_user_name)
- messages = process_messages(@user, @current_chat_user)
- render json: messages
- # else
- # if !@chat_with_users.empty?
- # @current_chat_user_name = @chat_with_users[0]["username"]
- # @current_chat_user = User.find_by(name: @current_chat_user_name)
- # @current_messages = Message.where(send_user: [@user.id, @current_chat_user_id], recieve_user:
- # [@user.id, @current_chat_user_id]).order(create_time: :asc)
- # end
+ if !@current_chat_user_name.nil?
+ messages = process_messages(@user, @current_chat_user)
+ render json: messages
+ end
end
end
def new
+ # 用户发送新的消息
+
@user = current_user
+ username = @user.name
+ userpic = @user.picurl
+
msg = params[:msg]
current_chat_user_name = params[:chat_with]
current_chat_user = User.find_by(name: current_chat_user_name)
save_time = DateTime.now
- msg_db = Message.new(content: msg, send_user: @user.id, recieve_user: current_chat_user.id, create_time: save_time, readed: false)
+ msg_db = Message.new(content: msg, send_user: @user.id, recieve_user: current_chat_user.id,
+ create_time: save_time, readed: false)
+
if msg_db.save
- render json: {msg: msg, time: save_time}
+ render json: {username: username, userpic: userpic, content: msg, time: save_time}
else
- render json: {msg: "error", time: save_time}
+ render json: {username: username, userpic: userpic, content: "error", time: save_time}
end
+
end
def notify
+ # 获取未读短信数
@user = current_user
- # unreaded_lists = unread_msg_users(@uesr)
render json: {unreaded: unread_msg_num(@user)}
end
def online
+ # # 获取未读短信和对对应的联系人
@user = current_user
results = unread_msg_users(@user)
if results.empty?
results = nil
end
- render json: {users:results}
+ render json: {users: results}
end
def query
+ # 添加新的联系人
@user = current_user
query_name = params[:username]
all_user_names = params[:all]
+ query_pic = String.new()
- if all_user_names.include? query_name or query_name == @user.name
- query_name = nil
- ok = false
- else
+ if all_user_names.nil?
query_user = User.find_by(name: query_name)
- if query_user.empty?
+ if query_user.nil?
query_name = nil
ok = false
else
query_name = query_user.name
+ query_pic = query_user.picurl
ok = true
end
+ else
+ if all_user_names.include? query_name or query_name == @user.name
+ query_name = nil
+ ok = false
+ else
+ query_user = User.find_by(name: query_name)
+ p "-----------here-------run----------"
+ if query_user.nil?
+ p "-----------here-------run----------"
+ query_name = nil
+ ok = false
+ else
+ query_name = query_user.name
+ query_pic = query_user.picurl
+ ok = true
+ end
+ end
end
- render json: {username: query_name, ok: ok}
+ render json: {username: query_name, userpic: query_pic, ok: ok}
end
end
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
new file mode 100644
index 0000000..73e23eb
--- /dev/null
+++ b/app/controllers/comments_controller.rb
@@ -0,0 +1,23 @@
+class CommentsController < ApplicationController
+ include CommentsHelper
+
+ def get
+ micropost_id = params["micropost_id"]
+ micropost_comments = get_micropost_comments micropost_id
+ render json: {comments:micropost_comments}
+ end
+
+ def new
+ @user = current_user
+ username = @user.name
+ userpic = @user.picurl
+ content = params[:content].to_s
+ micropost_id = params[:micropost_id]
+ if !content.empty? and !micropost_id.nil?
+ comments = @user.comments.new(content:content,micro_post_id:micropost_id,comment_time:DateTime.now)
+ comments.save
+ end
+ render json: {username: username, userpic: userpic}
+ end
+
+end
diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb
index 9f80274..b6c6cef 100644
--- a/app/controllers/main_controller.rb
+++ b/app/controllers/main_controller.rb
@@ -1,15 +1,30 @@
class MainController < ApplicationController
-
+ include MainHelper
before_action :logged_in_user
+
def show
@user = current_user
- p @user.email
- p gravatar_for @user
+ offset = 0
+ @micro_posts_array = read_newest_post(offset)
render 'main'
end
- def index
+ def activity
+ micro_post_id = params[:micropost_id]
+ join = params[:join].to_s
+ micro_post = MicroPost.find_by(id: micro_post_id)
+ if join == "true"
+ p "join activity"
+ micro_post.engage_people += 1
+ else
+ p "quit activity"
+ micro_post.engage_people -= 1
+ end
+ if micro_post.save
+ render json: {total_num: micro_post.engage_people}
+ end
+
end
end
diff --git a/app/controllers/micro_posts_controller.rb b/app/controllers/micro_posts_controller.rb
new file mode 100644
index 0000000..3255ca8
--- /dev/null
+++ b/app/controllers/micro_posts_controller.rb
@@ -0,0 +1,25 @@
+class MicroPostsController < ApplicationController
+ before_action :logged_in_user
+
+
+ def show
+ @user = current_user
+ @micro_posts = read_each_post @user
+ end
+
+ def new
+ @user = current_user
+
+ post_type = params[:post_type].to_i
+ title = params[:title].to_s
+ content = params[:content].to_s
+
+ if post_type >= 1 and post_type <= 3 and !title.empty? and !content.empty?
+ micropost = @user.micro_posts.new(content:content,post_time:DateTime.now,title:title,
+ post_type:post_type,engage_people:0)
+ micropost.save
+ end
+ redirect_to microposts_path
+ end
+
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3e3f1bd..c7e76ea 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -12,10 +12,16 @@ class UsersController < ApplicationController
end
end
+ def edit
+ @user = current_user
+ render 'edit'
+ end
+
private
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
+
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be79..a2f4870 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,3 @@
module ApplicationHelper
+
end
diff --git a/app/helpers/chat_helper.rb b/app/helpers/chat_helper.rb
index d5468f1..08e5af9 100644
--- a/app/helpers/chat_helper.rb
+++ b/app/helpers/chat_helper.rb
@@ -34,15 +34,20 @@ module ChatHelper
Message.transaction do
messages = Message.lock.where(send_user: [user.id, chat_with.id],
- recieve_user: [user.id, chat_with.id]).order(create_time: :asc)
- if !messages.empty?
+ recieve_user: [user.id, chat_with.id])
+
+ if messages.length >= 1
+ p "==================================="
+ messages = messages.order(create_time: :asc)
messages.each do |message|
if message.send_user == user.id
- x = {issend: true, send: user.name, recieve: chat_with.name, content: message.content, time: message.create_time}
+ x = {issend: true, name: user.name, userpic:user.picurl,
+ content: message.content, time: message.create_time}
else
message.readed = true
message.save
- x = {issend: false, send: chat_with.name, recieve: user.name, content: message.content, time: message.create_time}
+ x = {issend: false, name: chat_with.name, userpic:chat_with.picurl,
+ content: message.content, time: message.create_time}
end
results << x
end
@@ -56,17 +61,10 @@ module ChatHelper
end
def unread_msg_users user
- # unreaded_lists = []
- # unreaded_users = user.recieve_messages.where(readed: false).select(:send_user).distinct
- # if !unreaded_users.empty?
- # unreaded_users do |unreaded_id|
- # unreaded_lists << User.find(unreaded_id).id
- # end
- # end
- # unreaded_lists
+
return_user_msg = {}
results = user.recieve_messages.where(readed: false)
- if results.count != 0
+ if results.length != 0
results.each do |result|
username = User.find(result.send_user).name
return_user_msg[username] = [];
diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb
new file mode 100644
index 0000000..dc21312
--- /dev/null
+++ b/app/helpers/comments_helper.rb
@@ -0,0 +1,18 @@
+module CommentsHelper
+ def get_micropost_comments micropost_id
+ comments_array = Array.new()
+ micropost = MicroPost.find_by(id: micropost_id)
+ comments = micropost.comments
+ if !comments.empty?
+ comments.each do |com|
+ temp = Hash.new()
+ temp["username"] = com.user.name
+ temp["userpic"] = com.user.picurl
+ temp["content"] = com.content
+ comments_array << temp
+ end
+ end
+ return comments_array
+ end
+
+end
diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb
index 826effe..53f2032 100644
--- a/app/helpers/main_helper.rb
+++ b/app/helpers/main_helper.rb
@@ -1,2 +1,31 @@
module MainHelper
+
+ def read_newest_post offset_num
+ micro_posts_array = []
+ micro_posts = MicroPost.all.order(post_time: :desc).limit(20).offset(offset_num)
+ if !micro_posts.empty?
+ micro_posts.each do |micro_post|
+ x = Hash.new()
+ x["username"] = micro_post.user.name
+ x["userpic"] = micro_post.user.picurl
+ x["postid"] = micro_post.id
+ x["title"] = micro_post.title
+ x["content"] = micro_post.content
+ case micro_post.post_type
+ when 1
+ x["type"] = "新鲜事"
+ when 2
+ x["type"] = "组团信息"
+ when 3
+ x["type"] = "失物招领"
+ else
+ x["type"] = "新鲜事"
+ end
+ x["time"] = micro_post.post_time
+ x["peo_num"] = micro_post.engage_people
+ micro_posts_array << x
+ end
+ end
+ return micro_posts_array
+ end
end
diff --git a/app/helpers/micro_posts_helper.rb b/app/helpers/micro_posts_helper.rb
new file mode 100644
index 0000000..ac4c66d
--- /dev/null
+++ b/app/helpers/micro_posts_helper.rb
@@ -0,0 +1,31 @@
+module MicroPostsHelper
+
+ def read_each_post user
+ micro_posts_array = []
+ micro_posts = user.micro_posts.all.order(post_time: :desc)
+ if !micro_posts.empty?
+ micro_posts.each do |micro_post|
+ x = Hash.new()
+ x["title"] = micro_post.title
+ x["content"] = micro_post.content
+ case micro_post.post_type
+ when 1
+ x["type"] = "新鲜事"
+ when 2
+ x["type"] = "组团信息"
+ when 3
+ x["type"] = "失物招领"
+ else
+ x["type"] = "新鲜事"
+ end
+ x["time"] = micro_post.post_time
+ x["peo_num"] = micro_post.engage_people
+ micro_posts_array << x
+ end
+ end
+ return micro_posts_array
+ end
+
+
+
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 83f9e5f..4006c2b 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -2,6 +2,6 @@ module UsersHelper
def gravatar_for(user, options = { size: 80 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
- gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
+ gravatar_url = "https://secure.gravatar.com/avatars/#{gravatar_id}?s=#{size}"
end
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
new file mode 100644
index 0000000..3a0fb2f
--- /dev/null
+++ b/app/models/comment.rb
@@ -0,0 +1,4 @@
+class Comment < ApplicationRecord
+ belongs_to :user, class_name: 'User', foreign_key: 'user_id'
+ belongs_to :micro_post, class_name: 'MicroPost', foreign_key: 'micro_post_id'
+end
\ No newline at end of file
diff --git a/app/models/micro_post.rb b/app/models/micro_post.rb
new file mode 100644
index 0000000..2a2be7e
--- /dev/null
+++ b/app/models/micro_post.rb
@@ -0,0 +1,4 @@
+class MicroPost < ApplicationRecord
+ belongs_to :user, dependent: :destroy
+ has_many :comments, class_name: 'Comment', foreign_key: 'micro_post_id', dependent: :destroy
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 81afc00..f387ea9 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,6 +1,14 @@
class User < ApplicationRecord
+ before_save :default_values
+
+ def default_values
+ self.picurl = 'images/avatars/default/avatar.png'
+ end
+
has_many :send_messages, class_name: 'Message', foreign_key: 'send_user'
has_many :recieve_messages, class_name: 'Message', foreign_key: 'recieve_user'
+ has_many :micro_posts, dependent: :destroy
+ has_many :comments, class_name: 'Comment', foreign_key: 'user_id', dependent: :destroy
VALID_EMAIL_REGEX = /\A[\w+\-.]+@([a-z\d\-]+\.)+[a-z]+\z/i
before_save { self.email = email.downcase }
diff --git a/app/views/chat/index.html.erb b/app/views/chat/index.html.erb
index 15e57af..b621487 100644
--- a/app/views/chat/index.html.erb
+++ b/app/views/chat/index.html.erb
@@ -1,3 +1,5 @@
+<% provide(:title, @user.name) %>
+
@@ -5,49 +7,44 @@
-
-
-
@@ -72,11 +69,16 @@
-
-
+
\ No newline at end of file
diff --git a/app/views/index.html.erb b/app/views/index.html.erb
deleted file mode 100644
index a26047d..0000000
--- a/app/views/index.html.erb
+++ /dev/null
@@ -1,165 +0,0 @@
-
-
-
- <%= render 'layouts/nav' %>
-
-
-
-
-
-
-
-
-
-
- <%= @current_chat_user.name %>
-
-
- <% if !@current_chat_user.nil? %>
-
- <% @current_messages.each do |message| %>
- <% if message.send_user == @user.id %>
-
-
-
-
- <%= message.content %>
-
-
- <%= message.create_time %>
-
-
-
-
- <% else %>
-
-
-
-
<%= @current_chat_user.name %>
-
- <%= message.content %>
-
-
- <%= message.create_time %>
-
-
-
- <% end %>
- <% end %>
-
- <% end %>
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/views/layouts/_nav.html.erb b/app/views/layouts/_nav.html.erb
index 14c9351..4d1a452 100644
--- a/app/views/layouts/_nav.html.erb
+++ b/app/views/layouts/_nav.html.erb
@@ -3,9 +3,9 @@
-
+
@@ -77,7 +85,7 @@
$(document).ready(function () {
notify();
notify_num_ticker = setInterval('notify()', 10000);
- $("#msg").attr("disabled",true);
+ $("#msg").attr("disabled", true);
});
diff --git a/app/views/layouts/_refer.html.erb b/app/views/layouts/_refer.html.erb
index e89881a..39a0628 100644
--- a/app/views/layouts/_refer.html.erb
+++ b/app/views/layouts/_refer.html.erb
@@ -1,3 +1,8 @@
+
+
+
+
+
@@ -24,8 +29,10 @@
+
+
-
+
diff --git a/app/views/login/init.html.erb b/app/views/login/init.html.erb
index c627fd6..3a5f294 100644
--- a/app/views/login/init.html.erb
+++ b/app/views/login/init.html.erb
@@ -3,7 +3,7 @@
-
+
<%= form_tag(controller: "login", action: "login", method: "post") do %>
- 评论时间 -
-- 评论内容 -
-