socialforge/app/controllers/forums_controller.rb

103 lines
2.5 KiB
Ruby
Raw Normal View History

# added by fq
2013-11-22 10:24:15 +08:00
class ForumsController < ApplicationController
# GET /forums
# GET /forums.json
2013-11-22 10:24:15 +08:00
def index
@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
@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|
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
@offset, @limit = api_offset_and_limit({:limit => 10})
2013-11-22 10:24:15 +08:00
@forum = Forum.find(params[:id])
@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
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
@forum = Forum.new(params[:forum])
2013-11-22 21:55:21 +08:00
@forum.creator_id = User.current.id
respond_to do |format|
if @forum.save
format.html { redirect_to @forum, notice: l(:label_forum_create_succ) }
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])
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])
@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