2013-11-22 21:55:21 +08:00
|
|
|
class MemosController < ApplicationController
|
2013-11-23 10:47:28 +08:00
|
|
|
layout "base_memos"
|
2013-11-23 08:20:03 +08:00
|
|
|
def new
|
|
|
|
@memo = Memo.new
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.json { render json: @memo }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@memo = Memo.find(params[:id])
|
|
|
|
@replies = @memo.replies
|
2013-11-23 10:47:28 +08:00
|
|
|
@mome_new = Memo.new
|
2013-11-23 08:20:03 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.json { render json: @memo }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@memo = Memo.new(params[:memo])
|
|
|
|
@memo.author_id = User.current.id
|
2013-11-23 10:47:28 +08:00
|
|
|
@back_memo_id = @memo.id
|
|
|
|
|
|
|
|
if @memo.parent_id
|
|
|
|
@back_memo_id ||= @memo.parent_id
|
|
|
|
@parent_memo = Memo.find_by_id(@memo.parent_id)
|
|
|
|
@parent_memo.replies_count += 1
|
|
|
|
end
|
2013-11-23 08:20:03 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @memo.save
|
2013-11-23 10:47:28 +08:00
|
|
|
@parent_memo.last_reply_id = @memo.id if @parent_memo
|
|
|
|
if @parent_memo.save
|
|
|
|
format.html { redirect_to forum_memo_path(@memo.forum_id, @back_memo_id), notice: 'Memo was successfully created.' }
|
|
|
|
format.json { render json: @memo, status: :created, location: @memo }
|
|
|
|
else
|
|
|
|
format.html { redirect_to forum_memo_path(@memo.forum_id, @back_memo_id) }
|
|
|
|
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
|
|
|
end
|
2013-11-23 08:20:03 +08:00
|
|
|
else
|
|
|
|
format.html { render action: "new" }
|
|
|
|
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@memo = Memo.find(params[:id])
|
|
|
|
@memo.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to memos_url }
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
2013-11-22 21:55:21 +08:00
|
|
|
end
|