Class: PostsController

Inherits:
ForumBaseController show all
Defined in:
app/controllers/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/posts_controller.rb', line 57

def create
  @post.save!
  Radiant::Cache.clear if @post.page
  respond_to do |format|
    format.html { redirect_to_post }
    format.js { render :partial => 'post' }
  end
rescue ActiveRecord::RecordInvalid
  flash[:error] = t("forum_extension.validation_failure")
  respond_to do |format|
    format.html { render :action => 'new' }
    format.js { render :partial => 'form' }
  end
end

#destroyObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/posts_controller.rb', line 112

def destroy
  if @post.first?
    @post.topic.destroy
    flash[:notice] = t("forum_extension.topic_removed")
    redirect_to_forum
  else
    @post.destroy
    respond_to do |format|
      format.html { 
        flash[:notice] = t("forum_extension.post_removed")
        redirect_to_page_or_topic 
      }
      format.js { render :partial => 'post' }
    end
  end
end

#editObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/posts_controller.rb', line 72

def edit
  respond_to do |format| 
    format.html {
      @inline = false
      render
    }
    format.js { 
      @inline = true
      if current_reader.is_moderator?(@post) || @post.editable_by?(current_reader)
        render :partial => 'form' 
      else
        render :partial => 'ineditable' 
      end
    }
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/posts_controller.rb', line 9

def index
  @term = params[:q]
  posts = Post.visible_to(current_reader)
  posts = posts.matching(@term) unless @term.blank?
  posts = posts.from_reader(@reader) if @reader
  posts = posts.in_forum(@forum) if @forum
  posts = posts.in_topic(@topic) if @topic
  @posts = posts.paginate(pagination_parameters)
  respond_to do |format|
    format.html
    format.js { render :partial => 'search_results' }
    format.rss { render :layout => 'feed' }
  end
end

#newObject



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

def new
  unless @post.topic || @post.page
    if @forum ||= Forum.find_by_name(Radiant::Config['forum.default_forum'])
      @post.topic = @forum.topics.new
    else
      @post.topic = Topic.new
    end
  end
  respond_to do |format|
    format.html {
      @inline = false
      render
    }
    format.js {
      @inline = true
      if @post.page
        # page comment form is usually brought in by xhr so that page itself can be cached
        render :partial => 'pages/add_comment', :layout => false
      else
        # this is a much less common case, but you can cache topic pages if you really want to
        render :partial => 'topics/reply', :layout => false
      end
    }
  end
end

#removeObject



105
106
107
108
109
110
# File 'app/controllers/posts_controller.rb', line 105

def remove
  respond_to do |format|
    format.html { expires_now }
    format.js { render :partial => 'confirm_delete' }
  end
end

#showObject



24
25
26
27
28
29
# File 'app/controllers/posts_controller.rb', line 24

def show
  respond_to do |format|
    format.html { redirect_to_post }
    format.js { render :layout => false }
  end
end

#updateObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/posts_controller.rb', line 89

def update
  @post.attributes = params[:post]
  @post.save!
  Radiant::Cache.clear if @post.page || (@post.topic && Radiant.config['forum.cached?'])
  respond_to do |format|
    format.html { redirect_to_post }
    format.js { render :partial => 'post' }
  end
rescue ActiveRecord::RecordInvalid
  flash[:error] = t("forum_extension.validation_failure")
  respond_to do |format|
    format.html { render :action => 'edit' }
    format.js { render :partial => 'form' }
  end
end