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:
- 3261 Bytes
1 | class TopicsController < ApplicationController |
2 | before_filter :find_forum_and_topic, :except => :index |
3 | before_filter :login_required, :only => [:new, :create, :edit, :update, :destroy] |
4 | # before_filter :update_last_seen_at, :only => :show |
5 | |
6 | def index |
7 | respond_to do |format| |
8 | format.html { redirect_to forum_path(params[:forum_id]) } |
9 | format.xml do |
10 | @topics = Topic.find_all_by_forum_id(params[:forum_id], :order => 'sticky desc, replied_at desc', :limit => 25) |
11 | render :xml => @topics.to_xml |
12 | end |
13 | end |
14 | end |
15 | |
16 | def new |
17 | @topic = Topic.new |
18 | end |
19 | |
20 | def show |
21 | respond_to do |format| |
22 | format.html do |
23 | # see notes in application.rb on how this works |
24 | update_last_seen_at |
25 | # keep track of when we last viewed this topic for activity indicators |
26 | (session[:topics] ||= {})[@topic.id] = Time.now.utc if logged_in? |
27 | # authors of topics don't get counted towards total hits |
28 | @topic.hit! unless logged_in? and @topic.user == current_user |
29 | @post_pages, @posts = paginate(:posts, :per_page => 25, :order => 'posts.created_at', :include => :user, :conditions => ['posts.topic_id = ?', params[:id]]) |
30 | @voices = @posts.map(&:user) ; @voices.uniq! |
31 | @post = Post.new |
32 | end |
33 | format.xml do |
34 | render :xml => @topic.to_xml |
35 | end |
36 | format.rss do |
37 | @posts = @topic.posts.find(:all, :order => 'created_at desc', :limit => 25) |
38 | render :action => 'show.rxml', :layout => false |
39 | end |
40 | end |
41 | end |
42 | |
43 | def create |
44 | # this is icky - move the topic/first post workings into the topic model? |
45 | Topic.transaction do |
46 | @topic = @forum.topics.build(params[:topic]) |
47 | assign_protected |
48 | @topic.save! |
49 | @post = @topic.posts.build(params[:topic]) |
50 | @post.user = current_user |
51 | @post.save! |
52 | end |
53 | respond_to do |format| |
54 | format.html { redirect_to topic_path(@forum, @topic) } |
55 | format.xml { head :created, :location => formatted_topic_url(:forum_id => @forum, :id => @topic, :format => :xml) } |
56 | end |
57 | end |
58 | |
59 | def update |
60 | @topic.attributes = params[:topic] |
61 | assign_protected |
62 | @topic.save! |
63 | respond_to do |format| |
64 | format.html { redirect_to topic_path(@forum, @topic) } |
65 | format.xml { head 200 } |
66 | end |
67 | end |
68 | |
69 | def destroy |
70 | @topic.destroy |
71 | flash[:notice] = "Topic '#{CGI::escapeHTML @topic.title}' was deleted." |
72 | respond_to do |format| |
73 | format.html { redirect_to forum_path(@forum) } |
74 | format.xml { head 200 } |
75 | end |
76 | end |
77 | |
78 | protected |
79 | def assign_protected |
80 | @topic.user = current_user if @topic.new_record? |
81 | # admins and moderators can sticky and lock topics |
82 | return unless admin? or current_user.moderator_of?(@topic.forum) |
83 | @topic.sticky, @topic.locked = params[:topic][:sticky], params[:topic][:locked] |
84 | # only admins can move |
85 | return unless admin? |
86 | @topic.forum_id = params[:topic][:forum_id] if params[:topic][:forum_id] |
87 | end |
88 | |
89 | def find_forum_and_topic |
90 | @forum = Forum.find(params[:forum_id]) |
91 | @topic = @forum.topics.find(params[:id]) if params[:id] |
92 | end |
93 | |
94 | def authorized? |
95 | %w(new create).include?(action_name) || @topic.editable_by?(current_user) |
96 | end |
97 | end |