guoren/app/controllers/micro_posts_controller.rb

38 lines
971 B
Ruby

class MicroPostsController < ApplicationController
include MicroPostsHelper
before_action :logged_in_user
micro_posts_dir = "public/data"
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
pictures = params[:pictures]
if pictures
pictures.each do |pic|
pic.original_filename
ext = File.extname(pic.original_filename)
save_name = Digest::MD5::hexdigest(pic.original_filename) + ext
p save_name
end
end
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