guoren/app/controllers/comments_controller.rb

24 lines
660 B
Ruby
Raw Normal View History

2016-12-22 20:05:38 +08:00
class CommentsController < ApplicationController
include CommentsHelper
def get
micropost_id = params["micropost_id"]
micropost_comments = get_micropost_comments micropost_id
2016-12-26 11:00:51 +08:00
render json: {comments: micropost_comments}
2016-12-22 20:05:38 +08:00
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?
2016-12-26 11:00:51 +08:00
comments = @user.comments.new(content: content, micro_post_id: micropost_id, comment_time: DateTime.now)
2016-12-22 20:05:38 +08:00
comments.save
end
render json: {username: username, userpic: userpic}
end
end