Class: TopicsController

Inherits:
BaseController show all
Defined in:
app/controllers/topics_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from BaseHelper

#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #tiny_mce_init_if_needed, #tiny_mce_js, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject


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
# File 'app/controllers/topics_controller.rb', line 50

def create
  @topic = @forum.topics.new(topic_params)
  assign_protected

  @post = @topic.sb_posts.first
  if (!@post.nil?)
    @post.user = current_user
  end

  @topic.tag_list = params[:tag_list] || ''

  if !@topic.save
    respond_to do |format|
      format.html {
        render :action => 'new' and return
      }
    end
  else
    respond_to do |format|
      format.html {
        redirect_to forum_topic_path(@forum, @topic)
      }
      format.xml  {
        head :created, :location => forum_topic_url(:forum_id => @forum, :id => @topic, :format => :xml)
      }
    end
  end
end

#destroyObject


89
90
91
92
93
94
95
96
# File 'app/controllers/topics_controller.rb', line 89

def destroy
  @topic.destroy
  flash[:notice] = :topic_deleted.l_with_args(:topic => CGI::escapeHTML(@topic.title))
  respond_to do |format|
    format.html { redirect_to forum_path(@forum) }
    format.xml  { head 200 }
  end
end

#indexObject


9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/topics_controller.rb', line 9

def index
  @forum = Forum.find(params[:forum_id])
  respond_to do |format|
    format.html { redirect_to forum_path(params[:forum_id]) }
    format.xml do
      @topics = @forum.topics.order('sticky desc, replied_at desc').limit(25)
      render :xml => @topics.to_xml
    end
  end
end

#newObject


20
21
22
23
# File 'app/controllers/topics_controller.rb', line 20

def new
  @topic = Topic.new
  @topic.sb_posts.build
end

#showObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/topics_controller.rb', line 25

def show
  respond_to do |format|
    format.html do
      # see notes in base_controller.rb on how this works
      current_user.update_last_seen_at if logged_in?
      # keep track of when we last viewed this topic for activity indicators
      (session[:topics] ||= {})[@topic.id] = Time.now.utc if logged_in?
      # authors of topics don't get counted towards total hits
      @topic.hit! unless logged_in? and @topic.user == current_user

      @posts = @topic.sb_posts.recent.includes(:user).page(params[:page]).per(25)

      @voices = @posts.map(&:user).compact.uniq
      @post   = SbPost.new(params[:post])
    end
    format.xml do
      render :xml => @topic.to_xml
    end
    format.rss do
      @posts = @topic.sb_posts.recent.limit(25)
      render :action => 'show', :layout => false, :formats => [:xml]
    end
  end
end

#updateObject


79
80
81
82
83
84
85
86
87
# File 'app/controllers/topics_controller.rb', line 79

def update
  assign_protected
  @topic.tag_list = params[:tag_list] || ''
  @topic.update_attributes!(topic_params)
  respond_to do |format|
    format.html { redirect_to forum_topic_path(@forum, @topic) }
    format.xml  { head 200 }
  end
end