2016-12-22 20:00:08 +08:00
|
|
|
class MainController < ApplicationController
|
2016-12-22 20:05:38 +08:00
|
|
|
include MainHelper
|
2016-12-22 20:00:08 +08:00
|
|
|
before_action :logged_in_user
|
|
|
|
|
2016-12-22 20:05:38 +08:00
|
|
|
|
2016-12-22 20:00:08 +08:00
|
|
|
def show
|
|
|
|
@user = current_user
|
2016-12-26 15:36:00 +08:00
|
|
|
page_num = params[:page]
|
|
|
|
post_type = params[:type]
|
|
|
|
|
|
|
|
if !page_num
|
|
|
|
page_num = 1
|
|
|
|
end
|
|
|
|
if !post_type
|
|
|
|
post_type=[1,2,3]
|
|
|
|
end
|
|
|
|
|
|
|
|
@posts = MicroPost.where(post_type: post_type).paginate(:page => page_num, :per_page => 10).order(post_time: :desc)
|
|
|
|
@micro_posts_array = get_post(@posts)
|
2016-12-22 20:00:08 +08:00
|
|
|
render 'main'
|
2016-12-26 15:36:00 +08:00
|
|
|
|
2016-12-22 20:00:08 +08:00
|
|
|
end
|
|
|
|
|
2016-12-22 20:05:38 +08:00
|
|
|
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"
|
|
|
|
micro_post.engage_people += 1
|
|
|
|
else
|
|
|
|
micro_post.engage_people -= 1
|
|
|
|
end
|
|
|
|
if micro_post.save
|
|
|
|
render json: {total_num: micro_post.engage_people}
|
|
|
|
end
|
|
|
|
|
2016-12-22 20:00:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|