Class PostsController
In: app/controllers/posts_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

[Source]

     # File app/controllers/posts_controller.rb, line 122
122:   def confirm
123:     mailing_list_name = params["mailing_list_name"]
124:     @mailing_list = MailingList.find_by_name(mailing_list_name)
125:   end

[Source]

     # File app/controllers/posts_controller.rb, line 127
127:   def confirm_private_reply
128:     mailing_list_name = params["mailing_list_name"]
129:     @mailing_list = MailingList.find_by_name(mailing_list_name)
130:   end

Send email to local mail program. Don‘t save to database. Use mailing list‘s archiver to store posts. This strategy gives spam filters a change to reject bogus posts.

[Source]

    # File app/controllers/posts_controller.rb, line 76
76:   def create
77:     if params[:reply_to_id].present?
78:       post_private_reply
79:     else
80:       post_to_list
81:     end
82:   end

[Source]

    # File app/controllers/posts_controller.rb, line 2
 2:   def index
 3:     mailing_list_name = params["mailing_list_name"]
 4:     month_start = Time.zone.now.beginning_of_month
 5:     redirect_to(
 6:       :action => "list", 
 7:       :controller => "posts",
 8:       :month => month_start.month, 
 9:       :year => month_start.year, 
10:       :mailing_list_name => mailing_list_name
11:     )
12:   end

[Source]

    # File app/controllers/posts_controller.rb, line 14
14:   def list
15:     # TODO Refactor shaky if/else and date parsing logic
16:     # Could do SQL join instead, but paginate doesn't play nice or secure
17:     mailing_list_name = params["mailing_list_name"]
18:     @mailing_list = MailingList.find_by_name(mailing_list_name)
19:     if @mailing_list    
20:       requested_year = params["year"]
21:       requested_month = params["month"]
22:       begin
23:         raise "Invalid year" unless (1990..2099).include?(requested_year.to_i)
24:         raise "Invalid month" unless (1..12).include?(requested_month.to_i)
25:         
26:         if requested_year and requested_month
27:           month_start = Time.zone.local(requested_year.to_i, requested_month.to_i)
28:         end
29:       rescue
30:         month_start = Time.zone.now.beginning_of_month
31:         return redirect_to(
32:           :action => "list", 
33:           :month => month_start.month, 
34:           :year => month_start.year, 
35:           :mailing_list_name => mailing_list_name)
36:       end
37:     
38:       if params["previous"]
39:         month_start = month_start.months_ago(1)
40:         return redirect_to(:year => month_start.year, :month => month_start.month)
41:       elsif params["next"]
42:         month_start = month_start.next_month
43:         return redirect_to(:year => month_start.year, :month => month_start.month)
44:       end
45:     
46:       # end_of_month sets to 00:00
47:       month_end = month_start.end_of_month
48:       @year = month_start.year
49:       @month = month_start.month
50:     
51:       @posts = Post.find_for_dates(@mailing_list, month_start, month_end)
52:     else
53:       @mailing_lists = MailingList.find(:all)
54:       if mailing_list_name.blank?
55:         flash[:warn] = "Mailing list is required."
56:       else
57:         flash[:warn] = "Could not find mailing list named '#{mailing_list_name}.'"
58:       end
59:       render(:template => 'posts/404')
60:     end
61:   end

[Source]

     # File app/controllers/posts_controller.rb, line 112
112:   def new
113:     mailing_list_name = params["mailing_list_name"]
114:     @mailing_list = MailingList.find_by_name(mailing_list_name)
115:     @post = Post.new(:mailing_list => @mailing_list)
116:     if params[:reply_to_id].present?
117:       @reply_to = Post.find(params[:reply_to_id])
118:       @post.subject = "Re: #{@reply_to.subject}"
119:     end
120:   end

[Source]

    # File app/controllers/posts_controller.rb, line 84
84:   def post_private_reply
85:     @reply_to = Post.find(params[:reply_to_id])
86:     @post = Post.new(params[:post])
87:     @mailing_list = MailingList.find(@post.mailing_list_id)
88:     if @post.valid?
89:       private_reply_email = MailingListMailer.create_private_reply(@post, @reply_to.sender)
90:       MailingListMailer.deliver(private_reply_email)
91:       flash[:notice] = "Sent private reply '#{@post.subject}' to #{private_reply_email.to}"
92:       redirect_to(:action => "confirm_private_reply", :mailing_list_name => @mailing_list.name)
93:     else
94:       render(:action => "new", :reply_to_id => @reply_to.id)
95:     end
96:   end

[Source]

     # File app/controllers/posts_controller.rb, line 98
 98:   def post_to_list
 99:     @post = Post.new(params[:post])
100:     @mailing_list = MailingList.find(@post.mailing_list_id)
101:     @post.mailing_list = @mailing_list
102:     if @post.valid?
103:       post_email = MailingListMailer.create_post(@post)
104:       MailingListMailer.deliver(post_email)
105:       flash[:notice] = "Submitted new post: #{@post.subject}"
106:       redirect_to(:action => "confirm", :mailing_list_name => @mailing_list.name)
107:     else
108:       render(:action => "new")
109:     end
110:   end

[Source]

    # File app/controllers/posts_controller.rb, line 63
63:   def show
64:     if params["previous"]
65:       return redirect_to(:id => params["previous_id"])
66:     elsif params["next"]
67:       return redirect_to(:id => params["next_id"])
68:     end
69:     expires_in 1.hour, :public => true
70:     @post = Post.find(params["id"])
71:   end

[Validate]