forked from jonthewayne/altered_beast
-
Notifications
You must be signed in to change notification settings - Fork 1
/
topics_controller.rb
88 lines (76 loc) · 2.25 KB
/
topics_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class TopicsController < ApplicationController
before_filter :find_forum
before_filter :find_topic, :only => [:show, :edit, :update, :destroy]
def index
respond_to do |format|
format.html { redirect_to forum_path(@forum) }
format.xml do
@topics = find_forum.topics.paginate(:page => current_page)
render :xml => @topics
end
end
end
def edit
end
def show
respond_to do |format|
format.html do
if logged_in?
current_user.seen!
(session[:topics] ||= {})[@topic.id] = Time.now.utc
end
@topic.hit! unless logged_in? && @topic.user_id == current_user.id
@posts = @topic.posts.paginate :page => current_page
@post = Post.new
end
format.xml { render :xml => @topic }
end
end
def new
@topic = Topic.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @topic }
end
end
def create
@topic = current_user.post @forum, params[:topic]
respond_to do |format|
if @topic.new_record?
format.html { render :action => "new" }
format.xml { render :xml => @topic.errors, :status => :unprocessable_entity }
else
flash[:notice] = 'Topic was successfully created.'
format.html { redirect_to(forum_topic_path(@forum, @topic)) }
format.xml { render :xml => @topic, :status => :created, :location => forum_topic_url(@forum, @topic) }
end
end
end
def update
current_user.revise @topic, params[:topic]
respond_to do |format|
if @topic.errors.empty?
flash[:notice] = 'Topic was successfully updated.'
format.html { redirect_to(forum_topic_path(@forum, @topic)) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @topic.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@topic.destroy
respond_to do |format|
format.html { redirect_to(@forum) }
format.xml { head :ok }
end
end
protected
def find_forum
@forum = current_site.forums.find_by_permalink(params[:forum_id])
end
def find_topic
@topic = @forum.topics.find_by_permalink(params[:id])
end
end