mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-15 22:30:53 +00:00
24eabf89e6
Changed login field text Changed database configuration connection pool size to be configured via dotenv Use a single BBcode parser library Added better translations coverage Code formatting Increases maximum article text limit Added database cleaner with the deletion strategy during testing
80 lines
1.9 KiB
Ruby
80 lines
1.9 KiB
Ruby
class TopicsController < ApplicationController
|
|
before_filter :get_topic, :only => [:show, :reply, :edit, :update, :destroy]
|
|
|
|
def index
|
|
render :partial => true, :locals => {:page => params[:p].to_i}
|
|
end
|
|
|
|
def show
|
|
raise AccessError unless @topic.can_show? cuser
|
|
@posts = @topic.posts.basic.paginate(:page => params[:page],
|
|
:per_page => Topic::POSTS_PAGE)
|
|
|
|
return_here
|
|
@topic.record_view_count(request.remote_ip, cuser.nil?)
|
|
@topic.read_by! cuser if cuser
|
|
@topic.forum.read_by! cuser if cuser
|
|
@newpost = Post.new
|
|
@newpost.topic = @topic
|
|
@newpost.user = cuser
|
|
@lock = (@topic.lock ? @topic.lock : Lock.new(:lockable => @topic))
|
|
render :layout => "forums"
|
|
end
|
|
|
|
def reply
|
|
@post = @topic.posts.build
|
|
raise AccessError unless @post.can_create? cuser
|
|
if request.xhr?
|
|
render "quickreply", :layout => false
|
|
else
|
|
render :layout => "forums"
|
|
end
|
|
end
|
|
|
|
def new
|
|
@topic = Topic.new
|
|
@topic.forum = Forum.find(params[:id])
|
|
raise AccessError unless @topic.can_create? cuser
|
|
render :layout => "forums"
|
|
end
|
|
|
|
def edit
|
|
raise AccessError unless @topic.can_update? cuser
|
|
render :layout => "forums"
|
|
end
|
|
|
|
def create
|
|
@topic = Topic.new(params[:topic])
|
|
@topic.user = cuser
|
|
raise AccessError unless @topic.can_create? cuser
|
|
|
|
if @topic.save
|
|
flash[:notice] = t(:topics_create)
|
|
redirect_to(@topic)
|
|
else
|
|
render :action => "new"
|
|
end
|
|
end
|
|
|
|
def update
|
|
raise AccessError unless @topic.can_update? cuser
|
|
if @topic.update_attributes(params[:topic])
|
|
flash[:notice] = t(:topics_update)
|
|
redirect_to(@topic)
|
|
else
|
|
render :action => "edit"
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
raise AccessError unless @topic.can_destroy? cuser
|
|
@topic.destroy
|
|
redirect_to(topics_url)
|
|
end
|
|
|
|
private
|
|
|
|
def get_topic
|
|
@topic = Topic.find(params[:id])
|
|
end
|
|
end
|