2013-11-24 20:02:53 +08:00
|
|
|
# added by fq
|
2013-11-22 10:24:15 +08:00
|
|
|
class ForumsController < ApplicationController
|
|
|
|
# GET /forums
|
|
|
|
# GET /forums.json
|
2013-11-24 20:02:53 +08:00
|
|
|
|
2013-11-22 10:24:15 +08:00
|
|
|
def index
|
2013-11-24 20:02:53 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@forums_all = Forum.all
|
|
|
|
@forums_count = @forums_all.count
|
|
|
|
@forums_pages = Paginator.new @forums_count, @limit, params['page']
|
|
|
|
|
2013-11-22 10:24:15 +08:00
|
|
|
|
2013-11-24 20:02:53 +08:00
|
|
|
@offset ||= @forums_pages.offset
|
|
|
|
# @forums = @forums_all.offset(@offset).limit(@limit).all
|
|
|
|
@forums = Forum.all
|
2013-11-22 10:24:15 +08:00
|
|
|
respond_to do |format|
|
2013-11-22 20:03:56 +08:00
|
|
|
format.html # index.html.erb
|
|
|
|
format.json { render json: @forums }
|
2013-11-22 10:24:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /forums/1
|
|
|
|
# GET /forums/1.json
|
|
|
|
def show
|
2013-11-29 18:14:49 +08:00
|
|
|
@memo = Memo.new
|
2013-11-24 20:02:53 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
2013-11-22 10:24:15 +08:00
|
|
|
@forum = Forum.find(params[:id])
|
2013-11-24 20:02:53 +08:00
|
|
|
@memos_all = @forum.topics
|
|
|
|
@topic_count = @memos_all.count
|
|
|
|
@topic_pages = Paginator.new @topic_count, @limit, params['page']
|
|
|
|
|
|
|
|
@offset ||= @topic_pages.offset
|
|
|
|
@memos = @memos_all.offset(@offset).limit(@limit).all
|
2013-11-22 10:24:15 +08:00
|
|
|
respond_to do |format|
|
2013-11-23 20:31:48 +08:00
|
|
|
format.html {
|
|
|
|
render :layout => 'base_forums'
|
|
|
|
}# show.html.erb
|
2013-11-22 20:03:56 +08:00
|
|
|
format.json { render json: @forum }
|
2013-11-22 10:24:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /forums/new
|
|
|
|
# GET /forums/new.json
|
|
|
|
def new
|
|
|
|
@forum = Forum.new
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.json { render json: @forum }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /forums/1/edit
|
|
|
|
def edit
|
|
|
|
@forum = Forum.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /forums
|
|
|
|
# POST /forums.json
|
|
|
|
def create
|
2013-11-22 20:03:56 +08:00
|
|
|
@forum = Forum.new(params[:forum])
|
2013-11-22 21:55:21 +08:00
|
|
|
@forum.creator_id = User.current.id
|
2013-11-22 11:19:08 +08:00
|
|
|
|
2013-11-22 20:03:56 +08:00
|
|
|
respond_to do |format|
|
|
|
|
if @forum.save
|
2013-12-04 15:31:18 +08:00
|
|
|
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
|
2013-11-22 20:03:56 +08:00
|
|
|
format.json { render json: @forum, status: :created, location: @forum }
|
|
|
|
else
|
|
|
|
format.html { render action: "new" }
|
|
|
|
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
2013-11-22 10:24:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /forums/1
|
|
|
|
# PUT /forums/1.json
|
|
|
|
def update
|
|
|
|
@forum = Forum.find(params[:id])
|
|
|
|
|
2013-11-22 20:03:56 +08:00
|
|
|
respond_to do |format|
|
|
|
|
if @forum.update_attributes(params[:forum])
|
|
|
|
format.html { redirect_to @forum, notice: 'Forum was successfully updated.' }
|
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
|
|
|
format.html { render action: "edit" }
|
|
|
|
format.json { render json: @forum.errors, status: :unprocessable_entity }
|
2013-11-22 10:24:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /forums/1
|
|
|
|
# DELETE /forums/1.json
|
|
|
|
def destroy
|
|
|
|
@forum = Forum.find(params[:id])
|
2013-11-22 20:03:56 +08:00
|
|
|
@forum.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to forums_url }
|
|
|
|
format.json { head :no_content }
|
2013-11-22 10:24:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|