Class: Cornerstone::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Cornerstone::PostsController
- Defined in:
- app/controllers/cornerstone/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /cornerstone/discussions/:discussion_id/posts.
-
#destroy ⇒ Object
DELETE /cornerstone/discussions/:discussion_id/posts/:id.
-
#edit ⇒ Object
GET /cornerstone/discussions/:discussion_id/posts/:id/edit.
-
#update ⇒ Object
PUT /cornerstone/discussions/:discussion_id/posts/:id.
Instance Method Details
#create ⇒ Object
POST /cornerstone/discussions/:discussion_id/posts
6 7 8 9 10 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 |
# File 'app/controllers/cornerstone/posts_controller.rb', line 6 def create @discussion = Discussion.includes(:posts => :user).find(params[:discussion_id]) existing_posts = @discussion.posts.dup @post = @discussion.posts.new(params[:post]) # assign user if signed in if current_cornerstone_user @post.user = current_cornerstone_user end respond_with(@discussion, @post) do |format| if @post.save # close discussion if commit param dictates unless params[:comment_close].nil? @discussion.update_attribute(:status, Discussion::STATUS.last) else # re-open discussion if discussion is closed if @discussion.closed? @discussion.update_attribute(:status, Discussion::STATUS.first) end end flash[:notice] = 'Comment was successfully created.' format.html {redirect_to category_discussion_path(@discussion.category, @discussion)} else @new_post = @post @posts = existing_posts format.html {render :template => "cornerstone/discussions/show"} end end end |
#destroy ⇒ Object
DELETE /cornerstone/discussions/:discussion_id/posts/:id
56 57 58 59 60 61 62 |
# File 'app/controllers/cornerstone/posts_controller.rb', line 56 def destroy @post = Post.includes(:user, :discussion).find(params[:id]) raise Cornerstone::AccessDenied unless @post.created_by?(current_cornerstone_user) @discussion = @post.discussion flash[:notice] = "Post was successfully deleted." if @post.destroy respond_with(@discussion, @post, :location => category_discussion_path(@discussion.category, @discussion)) end |
#edit ⇒ Object
GET /cornerstone/discussions/:discussion_id/posts/:id/edit
39 40 41 42 43 44 |
# File 'app/controllers/cornerstone/posts_controller.rb', line 39 def edit @post = Post.includes(:user, :discussion).find(params[:id]) raise Cornerstone::AccessDenied unless @post.created_by?(current_cornerstone_user) @discussion = @post.discussion respond_with(@discussion, @post) end |
#update ⇒ Object
PUT /cornerstone/discussions/:discussion_id/posts/:id
47 48 49 50 51 52 53 |
# File 'app/controllers/cornerstone/posts_controller.rb', line 47 def update @post = Post.includes(:user, :discussion).find(params[:id]) raise Cornerstone::AccessDenied unless @post.created_by?(current_cornerstone_user) @discussion = @post.discussion flash[:notice] = "Post was successfully updated." if @post.update_attributes(params[:post]) respond_with(@discussion, @post, :location => category_discussion_path(@discussion.category, @discussion)) end |