Class: MongoidForums::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- MongoidForums::PostsController
- Defined in:
- app/controllers/mongoid_forums/posts_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
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 15 def create @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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 66 def destroy find_post if @topic.posts.first == @post flash[:alert] = "You may not delete the first post!" redirect_to @topic 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
45 46 47 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 45 def edit find_post end |
#new ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 7 def new @post = @topic.posts.build @post.topic = @topic.id if params[:reply_to_id] find_reply_to_post end end |
#show ⇒ Object
42 43 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 42 def show end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/mongoid_forums/posts_controller.rb', line 49 def update if @topic.locked? flash.alert = "You may not update a post on a locked topic!" redirect_to [@topic] and return end find_post if @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 |