Class: PlanMyStuff::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- PlanMyStuff::CommentsController
- Defined in:
- app/controllers/plan_my_stuff/comments_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /issues/:issue_id/comments.
-
#edit ⇒ Object
GET /issues/:issue_id/comments/:id/edit.
-
#update ⇒ Object
PATCH/PUT /issues/:issue_id/comments/:id.
Instance Method Details
#create ⇒ Object
POST /issues/:issue_id/comments
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 6 def create @issue = PMS::Issue.find(params[:issue_id].to_i, repo: params[:repo]) PMS::Comment.create!( issue: @issue, body: comment_params[:body], user: pms_current_user, visibility: comment_params[:visibility]&.to_sym || :public, waiting_on_reply: comment_params[:waiting_on_reply] == '1', ) flash[:success] = 'Comment was successfully created.' redirect_to(plan_my_stuff.issue_path(@issue.number, repo: @issue.repo.full_name)) rescue PMS::LockedIssueError flash[:error] = 'This issue is locked; no new comments can be posted.' redirect_to(plan_my_stuff.issue_path(@issue.number, repo: @issue.repo.full_name)) end |
#edit ⇒ Object
GET /issues/:issue_id/comments/:id/edit
25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 25 def edit load_comment return unless @comment return redirect_to_issue if issue_body_comment? @support_user = support_user? return if can_edit?(@comment) (plan_my_stuff.issue_path(@issue.number, repo: @issue.repo.full_name)) end |
#update ⇒ Object
PATCH/PUT /issues/:issue_id/comments/:id
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/plan_my_stuff/comments_controller.rb', line 37 def update load_comment return unless @comment return redirect_to_issue if issue_body_comment? @support_user = support_user? unless can_edit?(@comment) (plan_my_stuff.issue_path(@issue.number, repo: @issue.repo.full_name)) return end update_attrs = { body: comment_params[:body] } update_attrs[:visibility] = comment_params[:visibility].to_sym if @support_user && comment_params[:visibility] @comment.update!(**update_attrs) flash[:success] = 'Comment was successfully updated.' redirect_to(plan_my_stuff.issue_path(@issue.number, repo: @issue.repo.full_name)) rescue PMS::StaleObjectError flash.now[:error] = 'Comment was modified by someone else. Please review the latest changes and try again.' render(:edit, status: PMS.unprocessable_status) end |