socialforge/app/controllers/forums_controller.rb

103 lines
2.6 KiB
Ruby

# added by fq
class ForumsController < ApplicationController
# GET /forums
# GET /forums.json
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']
@offset ||= @forums_pages.offset
# @forums = @forums_all.offset(@offset).limit(@limit).all
@forums = Forum.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @forums }
end
end
# GET /forums/1
# GET /forums/1.json
def show
@memo = Memo.new
@offset, @limit = api_offset_and_limit({:limit => 10})
@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
respond_to do |format|
format.html {
render :layout => 'base_forums'
}# show.html.erb
format.json { render json: @forum }
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])
@forum.creator_id = User.current.id
respond_to do |format|
if @forum.save
format.html { redirect_to @forum, notice: 'Forum was successfully created.' }
format.json { render json: @forum, status: :created, location: @forum }
else
format.html { render action: "new" }
format.json { render json: @forum.errors, status: :unprocessable_entity }
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 }
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 }
end
end
end