Class: PostController
Constant Summary
PaginationHelper::DEFAULT_OPTIONS, PaginationHelper::OPTIONS
Instance Method Summary
collapse
included, #paginate, validate_options!
Instance Method Details
#destroy ⇒ Object
102
103
104
105
|
# File 'app/controllers/post_controller.rb', line 102
def destroy
current_user.posts.find(@params['id']).destroy rescue nil
redirect_to_main
end
|
112
113
114
115
|
# File 'app/controllers/post_controller.rb', line 112
def
Comment.find(@params['id']).destroy rescue nil
redirect_to @request.env['HTTP_REFERER']
end
|
#destroyxml ⇒ Object
107
108
109
110
|
# File 'app/controllers/post_controller.rb', line 107
def destroyxml
@postid = @params['id']
current_user.posts.find(@params['id']).destroy rescue nil
end
|
#edit ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'app/controllers/post_controller.rb', line 79
def edit
begin
@post = current_user.posts.find(@params['id'])
rescue ActiveRecord::RecordNotFound
redirect_to_main
return
end
if @request.post?
@post.attributes = @params['post']
if @post.save
flash['notice'] = "Post was successfully saved."
redirect_to_main
end
end
end
|
#index ⇒ Object
8
9
10
11
12
|
# File 'app/controllers/post_controller.rb', line 8
def index
@post_pages, @posts = paginate :posts,
:order_by => 'created_at DESC',
:per_page => @app_config['main']['num_posts']
end
|
#new ⇒ Object
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
|
# File 'app/controllers/post_controller.rb', line 52
def new
@post = Post.new
if @request.post?
@post.attributes = @params['post']
@post.user = current_user
@post. = current_user.
if @post.save
unless @params['tags'].empty?
@params['tags'].split(',').collect {|t| t.strip}.uniq.each do |tag|
thetag = Tag.find_by_tag(tag) || Tag.new('tag' => tag)
thetag.increment('numitems')
thetag.save
@post.tags << thetag
end
end
send_trackback(@post, @params['tb_url'], @app_config) unless @params['tb_url'].empty?
redirect_to :controller => 'users', :action => @post.user.username
return
end
@error = @post.errors.full_messages
return
end
end
|
#postxml ⇒ Object
96
97
98
99
100
|
# File 'app/controllers/post_controller.rb', line 96
def postxml
@post = current_user.posts.find(@params['id']) rescue Post.new
@post.update_attributes @params['post'] if @request.post?
render_without_layout 'post/postxml'
end
|
#range ⇒ Object
This is used for fancy URL viewing with URLs of the format /year/month/day.
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
|
# File 'app/controllers/post_controller.rb', line 21
def range
unless @params['year']
@error = 'Invalid date.'
render 'post/error'
return
end
if @params['day'] and !@params['month']
@error = 'Invalid date.'
render 'post/error'
return
end
year = @params['year']
fmonth = @params['month'] || '01'
tmonth = @params['month'] ? fmonth : '12'
fday = @params['day'] || '01'
tday = @params['day'] ? fday : '31'
tday = @params['day'] ? fday : (Time.mktime(year.to_i, tmonth.to_i + 1, 1) - 1.day).day.to_s rescue fday
if @params['user']
userid = User.find_by_username(@params['user']).id
@posts = Post.find_all(["created_at BETWEEN ? AND ? AND user_id=?", "#{year}-#{fmonth}-#{fday} 00:00:00", "#{year}-#{tmonth}-#{tday} 23:59:59", userid], 'created_at DESC') rescue []
else
@posts = Post.find_all(["created_at BETWEEN ? AND ?", "#{year}-#{fmonth}-#{fday} 00:00:00", "#{year}-#{tmonth}-#{tday} 23:59:59"], 'created_at DESC') rescue []
end
render_action 'index'
end
|
#reply ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'app/controllers/post_controller.rb', line 132
def reply
@post = Post.find_by_slug(@params['slug'])
unless @post.
redirect_to :controller => 'post', :action => 'view', :user => @post.user.username, :slug => @post.slug
return
end
if @params['id']
@comment = Comment.find @params['id']
end
if @request.post?
@newcomment = @comment ? @comment..create(@params['newcomment']) : @post..create(@params['newcomment'])
if @newcomment.save
redirect_to :controller => 'post', :action => 'view', :user => @post.user.username, :slug => @post.slug
end
end
@newcomment = Comment.new('subject' => 'Re: ' + @post.subject)
end
|
#replyxml ⇒ Object
156
157
158
159
160
161
|
# File 'app/controllers/post_controller.rb', line 156
def replyxml
@post = Post.find(@params['id'])
@params['comment']['body'].strip! @comment = @post..create(@params['comment'])
render_without_layout 'post/replyxml'
end
|
117
118
119
120
121
122
123
|
# File 'app/controllers/post_controller.rb', line 117
def
if (post = current_user.posts.find(@params['id']) rescue nil)
post. = (not post.)
post.save
end
redirect_to @request.env['HTTP_REFERER']
end
|
125
126
127
128
129
130
|
# File 'app/controllers/post_controller.rb', line 125
def
if (@post = current_user.posts.find(@params['id']) rescue nil)
@post. = (not @post.)
@post.save
end
end
|
#view ⇒ Object
14
15
16
17
18
|
# File 'app/controllers/post_controller.rb', line 14
def view
@post = Post.find_by_sql("SELECT p.* FROM posts p, users u WHERE p.slug='#{@params['slug']}' AND u.username='#{@params['user']}' and p.user_id=u.id")[0]
redirect_to_main and return if @post.nil?
@comments = @post.("comment_id=0")
end
|