Class: MongoidForums::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- MongoidForums::PostsController
- Defined in:
- app/controllers/mongoid_forums/posts_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 17 def create :reply, @topic @post = @topic.posts.build(post_params) @post.user = mongoid_forums_user if @post.reply_to_id && @post.reply_to_id == @topic.posts.first.id flash[:alert] = "You may not quote the original post" redirect_to @topic return end if @topic.locked flash[:alert] = "You may not post on a locked topic" redirect_to @topic return end if @post.save @topic.alert_subscribers(mongoid_forums_user.id) @topic.forum.increment_posts_count flash[:notice] = "Reply created successfully" redirect_to @topic else flash.now.alert = "Reply could not be created" render :action => "new" end end |
#destroy ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 71 def destroy find_post if @topic.posts.first == @post flash[:alert] = "You may not delete the first post!" redirect_to @topic return end :destroy_post, @topic.forum unless @post.owner_or_admin? mongoid_forums_user flash[:alert] = t("mongoid_forums.post.cannot_delete") redirect_to @topic and return end if @post.destroy flash[:notice] = "Post deleted successfully" redirect_to @topic else flash[:notice] = "Post could not be deleted" redirect_to @topic end end |
#edit ⇒ Object
48 49 50 51 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 48 def edit find_post :edit_post, @topic.forum end |
#new ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 8 def new :reply, @topic @post = @topic.posts.build @post.topic = @topic.id if params[:reply_to_id] find_reply_to_post end end |
#show ⇒ Object
45 46 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 45 def show end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 53 def update if @topic.locked? flash.alert = "You may not update a post on a locked topic!" redirect_to [@topic] and return end :edit_post, @topic.forum find_post if @post.owner_or_admin?(mongoid_forums_user) && @post.update_attributes(post_params) flash[:notice] = "Reply updated successfully" redirect_to @topic else flash[:notice] = "Reply could not be updated" render :action => "edit" end end |