Class: SimpleForum::TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_forum/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/simple_forum/topics_controller.rb', line 76

def close
  success = if @topic.is_open?
              @topic.close!
              true
            else
              false
            end

  respond_to do |format|
    format.html do
      if success
        redirect_to :back, :notice => t('simple_forum.controllers.topics.topic_closed')
      else
        redirect_to :back, :alert => t('simple_forum.controllers.topics.topic_already_closed')
      end
    end
  end
end

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/simple_forum/topics_controller.rb', line 41

def create
  success = @topic.save

  respond_to do |format|
    format.html do
      if success
        flash[:notice] = t('simple_forum.controllers.topics.topic_created')
        redirect_to simple_forum.forum_topic_url(@forum, @topic)
      else
        flash.now[:alert] = @topic.errors.full_messages.join(' ')
        render :new
      end
    end
  end
end

#indexObject



13
14
15
16
17
18
19
20
# File 'app/controllers/simple_forum/topics_controller.rb', line 13

def index

  respond_to do |format|
    format.html do
      redirect_to simple_forum.forum_url(@forum), :status => :moved_permanently
    end
  end
end

#newObject



36
37
38
39
# File 'app/controllers/simple_forum/topics_controller.rb', line 36

def new

  respond_with(@topic)
end

#openObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/simple_forum/topics_controller.rb', line 57

def open
  success = if @topic.is_open?
              false
            else
              @topic.open!
              true
            end

  respond_to do |format|
    format.html do
      if success
        redirect_to :back, :notice => t('simple_forum.controllers.topics.topic_opened')
      else
        redirect_to :back, :alert => t('simple_forum.controllers.topics.topic_already_opened')
      end
    end
  end
end

#showObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/simple_forum/topics_controller.rb', line 22

def show
  bang_simple_forum_recent_activity(@topic)
  @topic.increment_views_count

  @posts_search = @topic.posts.includes([:user, :deleted_by, :edited_by])
  @posts = @posts_search.respond_to?(:paginate) ?
      @posts_search.paginate(:page => params[:page], :per_page => params[:per_page] || SimpleForum::Post.per_page) :
      @posts_search.all

  @post = SimpleForum::Post.new

  respond_with(@topic)
end