Class: TopicsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/forum_monster/templates/controllers/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 12

def create
  @forum = Forum.find(params[:forum_id])
  @topic = @forum.topics.build(params[:topic])
  @topic.user = current_user
  
  if @topic.save
    flash[:notice] = "Topic was successfully created."
    redirect_to topic_url(@topic)
  else
    render :action => 'new'
  end
end

#destroyObject



38
39
40
41
42
43
44
45
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 38

def destroy
  @topic = Topic.find(params[:id])
  
  if @topic.destroy
    flash[:notice] = "Topic was deleted successfully."
    redirect_to forum_url(@topic.forum)
  end
end

#editObject



25
26
27
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 25

def edit
  @topic = Topic.find(params[:id])
end

#newObject



7
8
9
10
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 7

def new
  @forum = Forum.find(params[:forum_id])
  @topic = Topic.new
end

#showObject



2
3
4
5
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 2

def show
  @topic = Topic.find(params[:id])
  @topic.hit! if @topic
end

#updateObject



29
30
31
32
33
34
35
36
# File 'lib/generators/forum_monster/templates/controllers/topics_controller.rb', line 29

def update
  @topic = Topic.find(params[:id])
  
  if @topic.update_attributes(params[:topic])
    flash[:notice] = "Topic was updated successfully."
    redirect_to topic_url(@topic)
  end
end