guoren/app/controllers/micro_posts_controller.rb

37 lines
908 B
Ruby
Raw Normal View History

2016-12-22 20:05:38 +08:00
class MicroPostsController < ApplicationController
2016-12-26 11:00:51 +08:00
include MicroPostsHelper
2016-12-22 20:05:38 +08:00
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
2016-12-25 22:18:43 +08:00
pictures = params[:pictures]
2016-12-26 11:00:51 +08:00
if pictures
2016-12-26 14:24:20 +08:00
pic_path = Array.new
2016-12-26 11:00:51 +08:00
pictures.each do |pic|
2016-12-26 14:24:20 +08:00
savename = savePicture(pic)
pic_path << savename
2016-12-26 11:00:51 +08:00
end
2016-12-26 14:24:20 +08:00
pic_path = pic_path.join(',')
2016-12-25 22:18:43 +08:00
end
2016-12-22 20:05:38 +08:00
if post_type >= 1 and post_type <= 3 and !title.empty? and !content.empty?
2016-12-26 14:24:20 +08:00
micropost = @user.micro_posts.new(title: title, content: content, pic: pic_path,
post_time: DateTime.now, post_type: post_type, engage_people: 0)
2016-12-22 20:05:38 +08:00
micropost.save
end
redirect_to microposts_path
end
end