Class: MongoidForums::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 11

def create

  @post = Post.new
  @post.text = params[:post][:text]
  @post.topic = params[:topic_id]
  @post.user = mongoid_forums_user.id
  @post.reply_to_id = params[:post][:reply_to_id]

  if @post.reply_to_id && @post.reply_to_id == @post.topic.posts.first.id
    flash[:alert] = "You may not quote the original post"
    redirect_to @post.topic
    return
  end


  if @post.topic.locked
    flash[:alert] = "You may not post on a locked topic"
    redirect_to @post.topic
    return
  end

  if @post.save
    @post.topic.alert_subscribers(mongoid_forums_user.id)
    flash[:notice] = "Reply created successfully"
    redirect_to @post.topic
  else
    flash.now.alert = "Reply could not be created"
    render :action => "new"
  end
end

#destroyObject



60
61
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 60

def destroy
end

#editObject



45
46
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 45

def edit
end

#newObject



5
6
7
8
9
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 5

def new
  @topic = Topic.find(params[:topic_id])
  @post = Post.new
  @post.topic = @topic.id
end

#showObject



42
43
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 42

def show
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 48

def update
  @post = current_resource

  if @post.update_attributes(post_params)
    flash[:notice] = "Reply updated successfully"
    redirect_to current_resource.topic
  else
    flash[:notice] = "Reply could not be updated"
    render :action => "edit"
  end
end