This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts_controller.rb
More file actions
144 lines (118 loc) · 5.09 KB
/
Copy pathposts_controller.rb
File metadata and controls
144 lines (118 loc) · 5.09 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# $Id$
class PostsController < ApplicationController
before_filter :check_for_person_logged_in, :only => [:new, :create, :comment_on_post, :index_for_current_person]
before_filter :check_for_ownership, :only => [:edit, :update, :delete]
before_filter :set_current_tab
def index
@title = 'The latest'
@pages, @posts = paginate :post, :order => 'created_on desc'
respond_to do |format|
format.html
format.atom { render :action => 'feeds/index', :layout => false }
format.xml { render :xml => @posts.to_xml(:include => :person) }
end
end
def index_by_date
date = params[:year]
date += "-#{params[:month]}" if params[:month]
date += "-#{params[:day]}" if params[:day]
@title = "The posts @ #{date}"
@pages, @posts = paginate :post, :conditions => ['created_on like ?', "#{date}%"], :order => 'created_on desc'
respond_to do |format|
format.html { render :action => 'index' }
format.atom { render :action => 'feeds/index', :layout => false }
format.xml { render :xml => @posts.to_xml(:include => :person) }
end
end
def index_for_current_person
params[:account_name] = current_person.account_name
index_for_account_name
end
def index_for_account_name
@title = "The posts by #{params[:account_name]}"
@pages, @posts = paginate :post, :conditions => ['people.account_name=?', params[:account_name]], :include => :person, :order => 'posts.created_on desc'
respond_to do |format|
format.html { render :action => 'index' }
format.atom { render :action => 'feeds/index', :layout => false }
format.xml { render :xml => @posts.to_xml(:include => :person) }
end
end
def index_by_date_for_account_name
date = params[:year]
date += "-#{params[:month]}" if params[:month]
date += "-#{params[:day]}" if params[:day]
@title = "The posts by #{params[:account_name]} @ #{date}"
@pages, @posts = paginate :post,
:conditions => ['posts.created_on like ? and people.account_name=?', "#{date}%", params[:account_name]],
:include => :person,
:order => 'posts.created_on desc'
respond_to do |format|
format.html { render :action => 'index' }
format.atom { render :action => 'feeds/index', :layout => false }
format.xml { render :xml => @posts.to_xml(:include => :person) }
end
end
def get_by_permalink_for_account_name
@post = Post.find_by_permalink_for_account_name(params[:permalink], params[:account_name])
unless @post.nil?
@title = @post.title
@post.is_selected = true
end
respond_to do |format|
format.html { render :action => 'show' }
format.atom { render :action => 'feeds/show', :layout => false }
format.xml { render :xml => @post.to_xml(:include => :person) }
end
end
def create
@title = 'Make a post'
@current_tab = :posts_post
@post = Post.new(params[:post])
if request.post? && @post.save
flash[:notice] = '<strong>Yay!</strong> Your post has been created.'
redirect_to url_for_post(@post)
else
render :action => 'new'
end
end
def edit
@title = 'Edit your post'
@post = Post.find_by_permalink_for_account_name(params[:permalink], params[:account_name])
end
def update
@post = Post.find_by_permalink_for_account_name(params[:permalink], params[:account_name])
if @post.update_attributes(params[:post])
flash[:notice] = '<strong>Woo!</strong> Your post has been updated.'
redirect_to url_for_post(@post)
else
render :action => 'edit'
end
end
def url_for_post(post)
url_for(:controller => 'posts',
:action => 'get_by_permalink_for_account_name',
:account_name => post.person.account_name,
:permalink => post.permalink,
:year => post.created_year,
:month => post.created_month,
:day => post.created_day)
end
def comment_on_post
@post = Post.find_by_permalink_for_account_name(params[:permalink], params[:account_name])
unless @post.nil?
@comment = Comment.new(params[:comment])
@comment.person = current_person
@post.comments << @comment
redirect_url = url_for_post(@post)
if @comment.save
redirect_url += "#comment-#{@comment.id}"
end
redirect_to redirect_url
else
redirect_to url_for(:controller => 'posts')
end
end
def set_current_tab
@current_tab = :posts
end
end