guoren/app/controllers/main_controller.rb

40 lines
831 B
Ruby

class MainController < ApplicationController
include MainHelper
before_action :logged_in_user
def show
@user = current_user
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)
render 'main'
end
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
end
end