|
|
|
@ -73,41 +73,14 @@ class MemosController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
|
|
|
|
|
format.json { render json: @memo, status: :created, location: @memo }
|
|
|
|
|
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
|
|
|
|
|
format.json { render json: @memo, status: :created, location: @memo }
|
|
|
|
|
else
|
|
|
|
|
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
|
|
|
|
|
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
|
|
|
|
|
pre_count = REPLIES_PER_PAGE
|
|
|
|
|
|
|
|
|
|
@memo_new = @memo.dup
|
|
|
|
|
@memo = @memo.root # 取出楼主,防止输入帖子id让回复作为主贴显示
|
|
|
|
|
unless @memo.new_record?
|
|
|
|
|
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page = params[:page]
|
|
|
|
|
if params[:r] && page.nil?
|
|
|
|
|
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
|
|
|
|
|
page = 1 + offset / pre_count
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
@reply_count = @memo.children.count
|
|
|
|
|
@reply_pages = Paginator.new @reply_count, pre_count, page
|
|
|
|
|
@replies = @memo.children.
|
|
|
|
|
includes(:author, :attachments).
|
|
|
|
|
reorder("#{Memo.table_name}.created_at DESC").
|
|
|
|
|
limit(@reply_pages.per_page).
|
|
|
|
|
offset(@reply_pages.offset).
|
|
|
|
|
all
|
|
|
|
|
if @memo.new_record?
|
|
|
|
|
format.html { render :new,:layout=>'base_forums'}
|
|
|
|
|
else
|
|
|
|
|
format.html { render action: :show }
|
|
|
|
|
format.js
|
|
|
|
|
format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) }
|
|
|
|
|
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|