Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 173
- Log:
Updated to latest release of Beast according to the "getting started with
Beast" guide at:http://beast.caboo.se/forums/1/topics/381
This check-in includes frozen Edge Rails and has the beginnings of
configuration for the ROOL site included.
- Author:
- rool
- Date:
- Fri Mar 02 15:59:12 +0000 2007
- Size:
- 4925 Bytes
1 | class PostsController < ApplicationController |
2 | before_filter :find_post, :except => [:index, :create, :monitored, :search] |
3 | before_filter :login_required, :except => [:index, :monitored, :search, :show] |
4 | @@query_options = { :per_page => 25, :select => 'posts.*, topics.title as topic_title, forums.name as forum_name', :joins => 'inner join topics on posts.topic_id = topics.id inner join forums on topics.forum_id = forums.id', :order => 'posts.created_at desc' } |
5 | |
6 | def index |
7 | conditions = [] |
8 | [:user_id, :forum_id].each { |attr| conditions << Post.send(:sanitize_sql, ["posts.#{attr} = ?", params[attr]]) if params[attr] } |
9 | conditions = conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil |
10 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions)) |
11 | @users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) |
12 | render_posts_or_xml |
13 | end |
14 | |
15 | def search |
16 | conditions = params[:q].blank? ? nilil : Post.send(:sanitize_sql, ['LOWER(posts.body) LIKE ?', "%#{params[:q]}%"]) |
17 | @post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions)) |
18 | @users = User.find(:all, :select => 'distinct *', :conditions => ['id in (?)', @posts.collect(&:user_id).uniq]).index_by(&:id) |
19 | render_posts_or_xml :index |
20 | end |
21 | |
22 | def monitored |
23 | @user = User.find params[:user_id] |
24 | options = @@query_options.merge(:conditions => ['monitorships.user_id = ? and posts.user_id != ?', params[:user_id], @user.id]) |
25 | options[:joins] += ' inner join monitorships on monitorships.topic_id = topics.id' |
26 | @post_pages, @posts = paginate(:posts, options) |
27 | render_posts_or_xml |
28 | end |
29 | |
30 | def show |
31 | respond_to do |format| |
32 | format.html { redirect_to topic_path(@post.forum_id, @post.topic_id) } |
33 | format.xml { render :xml => @post.to_xml } |
34 | end |
35 | end |
36 | |
37 | def create |
38 | @topic = Topic.find_by_id_and_forum_id(params[:topic_id],params[:forum_id], :include => :forum) |
39 | if @topic.locked? |
40 | respond_to do |format| |
41 | format.html do |
42 | flash[:notice] = 'This topic is locked.' |
43 | redirect_to(topic_path(:forum_id => params[:forum_id], :id => params[:topic_id])) |
44 | end |
45 | format.xml do |
46 | render :text => 'This topic is locked.', :status => 400 |
47 | end |
48 | end |
49 | return |
50 | end |
51 | @forum = @topic.forum |
52 | @post = @topic.posts.build(params[:post]) |
53 | @post.user = current_user |
54 | @post.save! |
55 | respond_to do |format| |
56 | format.html do |
57 | redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1') |
58 | end |
59 | format.xml { head :created, :location => formatted_post_url(:forum_id => params[:forum_id], :topic_id => params[:topic_id], :id => @post, :format => :xml) } |
60 | end |
61 | rescue ActiveRecord::RecordInvalid |
62 | flash[:bad_reply] = 'Please post something at least...' |
63 | respond_to do |format| |
64 | format.html do |
65 | redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => 'reply-form', :page => params[:page] || '1') |
66 | end |
67 | format.xml { render :xml => @post.errors.to_xml, :status => 400 } |
68 | end |
69 | end |
70 | |
71 | def edit |
72 | respond_to do |format| |
73 | format.html |
74 | format.js |
75 | end |
76 | end |
77 | |
78 | def update |
79 | @post.attributes = params[:post] |
80 | @post.save! |
81 | rescue ActiveRecord::RecordInvalid |
82 | flash[:bad_reply] = 'An error occurred' |
83 | ensure |
84 | respond_to do |format| |
85 | format.html do |
86 | redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1') |
87 | end |
88 | format.js |
89 | format.xml { head 200 } |
90 | end |
91 | end |
92 | |
93 | def destroy |
94 | @post.destroy |
95 | flash[:notice] = "Post of '#{CGI::escapeHTML @post.topic.title}' was deleted." |
96 | # check for posts_count == 1 because its cached and counting the currently deleted post |
97 | @post.topic.destroy and redirect_to forum_path(params[:forum_id]) if @post.topic.posts_count == 1 |
98 | respond_to do |format| |
99 | format.html do |
100 | redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :page => params[:page]) unless performed? |
101 | end |
102 | format.xml { head 200 } |
103 | end |
104 | end |
105 | |
106 | protected |
107 | def authorized? |
108 | action_name == 'create' || @post.editable_by?(current_user) |
109 | end |
110 | |
111 | def find_post |
112 | @post = Post.find_by_id_and_topic_id_and_forum_id(params[:id], params[:topic_id], params[:forum_id]) || raise(ActiveRecord::RecordNotFound) |
113 | end |
114 | |
115 | def render_posts_or_xml(template_name = action_name) |
116 | respond_to do |format| |
117 | format.html { render :action => "#{template_name}.rhtml" } |
118 | format.rss { render :action => "#{template_name}.rxml", :layout => false } |
119 | format.xml { render :xml => @posts.to_xml } |
120 | end |
121 | end |
122 | end |