Class: CoPlan::PlansController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- CoPlan::PlansController
- Defined in:
- app/controllers/coplan/plans_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#edit ⇒ Object
18 19 20 |
# File 'app/controllers/coplan/plans_controller.rb', line 18 def edit (@plan, :update?) end |
#index ⇒ Object
5 6 7 8 9 |
# File 'app/controllers/coplan/plans_controller.rb', line 5 def index @plans = Plan.order(updated_at: :desc) @plans = @plans.where(status: params[:status]) if params[:status].present? @plans = @plans.where(created_by_user: current_user) if params[:scope] == "mine" end |
#show ⇒ Object
11 12 13 14 15 16 |
# File 'app/controllers/coplan/plans_controller.rb', line 11 def show (@plan, :show?) threads = @plan.comment_threads.includes(:comments, :created_by_user, :plan_version).order(created_at: :asc) @active_threads = threads.active @archived_threads = threads.archived end |
#update ⇒ Object
22 23 24 25 26 27 |
# File 'app/controllers/coplan/plans_controller.rb', line 22 def update (@plan, :update?) @plan.update!(title: params[:plan][:title]) broadcast_plan_update(@plan) redirect_to plan_path(@plan), notice: "Plan updated." end |
#update_status ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/coplan/plans_controller.rb', line 29 def update_status (@plan, :update_status?) new_status = params[:status] if Plan::STATUSES.include?(new_status) && @plan.update(status: new_status) broadcast_plan_update(@plan) if @plan.saved_change_to_status? Plans::TriggerAutomatedReviews.call(plan: @plan, new_status: new_status, triggered_by: current_user) end redirect_to plan_path(@plan), notice: "Status updated to #{new_status}." else redirect_to plan_path(@plan), alert: "Invalid status." end end |