Class: TopicsController

Inherits:
ApplicationController show all
Defined in:
lib/generators/squeezer/templates/app/controllers/topics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#latests, #site

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 17

def create
  @topic = Topic.new(params[:topic])
  @topic=Comment.add_comment(@topic)
  Comment.add_post(@topic.comment.id,params[:post][:body])
  
  flash[:notice]="Listo!"
  redirect_to @topic
end

#destroyObject



40
41
42
43
44
45
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 40

def destroy
  @topic = Topic.find(params[:id])
  @topic.destroy
  flash[:notice] = "Successfully destroyed topic."
  redirect_to topics_url
end

#editObject



26
27
28
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 26

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

#indexObject



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

def index
  @topics = Topic.all
end

#newObject



11
12
13
14
15
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 11

def new
  @topic = Topic.new
  @topic.forum_id=params[:id]
  @post = Post.new 
end

#showObject



6
7
8
9
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 6

def show
  @topic = Topic.find(params[:id])
  Comment.posts(@topic)
end

#updateObject



30
31
32
33
34
35
36
37
38
# File 'lib/generators/squeezer/templates/app/controllers/topics_controller.rb', line 30

def update
  @topic = Topic.find(params[:id])
  if @topic.update_attributes(params[:topic])
    flash[:notice] = "Successfully updated topic."
    redirect_to @topic
  else
    render :action => 'edit'
  end
end