Class: PlanMyStuff::ProjectsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PlanMyStuff::ProjectsController
- Defined in:
- app/controllers/plan_my_stuff/projects_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /projects.
-
#edit {|@project| ... } ⇒ Object
GET /projects/:id/edit.
-
#index {|@projects| ... } ⇒ Object
GET /projects.
-
#new {|@project| ... } ⇒ Object
GET /projects/new.
-
#show {|@project| ... } ⇒ Object
GET /projects/:id.
-
#update ⇒ Object
PATCH/PUT /projects/:id.
Instance Method Details
#create ⇒ Object
POST /projects
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 27 def create @project = PlanMyStuff::Project.create!( title: project_params[:title], readme: project_params[:readme] || '', description: project_params[:description], user: pms_current_user, ) yield(@project) if block_given? return if performed? flash[:success] = 'Project was successfully created.' redirect_to(plan_my_stuff.project_path(@project.number)) rescue PlanMyStuff::ValidationError => e pms_handle_rescue(e) @project = PlanMyStuff::Project.new( title: project_params[:title], readme: project_params[:readme], description: project_params[:description], ) flash.now[:error] = e. render(:new, status: PlanMyStuff.unprocessable_status) end |
#edit {|@project| ... } ⇒ Object
GET /projects/:id/edit
61 62 63 64 65 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 61 def edit @project = PlanMyStuff::Project.find(params[:id].to_i) yield(@project) if block_given? end |
#index {|@projects| ... } ⇒ Object
GET /projects
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 6 def index all_projects = PlanMyStuff::BaseProject.list.reject(&:closed) @filter = params[:filter].presence_in(%w[testing all]) || 'regular' @projects = case @filter when 'testing' then all_projects.select { |p| p.is_a?(PlanMyStuff::TestingProject) } when 'regular' then all_projects.reject { |p| p.is_a?(PlanMyStuff::TestingProject) } else all_projects end yield(@projects) if block_given? end |
#new {|@project| ... } ⇒ Object
GET /projects/new
20 21 22 23 24 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 20 def new @project = PlanMyStuff::Project.new yield(@project) if block_given? end |
#show {|@project| ... } ⇒ Object
GET /projects/:id
52 53 54 55 56 57 58 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 52 def show @project = PlanMyStuff::Project.find(params[:id].to_i) @statuses = @project.statuses.pluck(:name) @items_by_status = @project.items.group_by(&:status) yield(@project) if block_given? end |
#update ⇒ Object
PATCH/PUT /projects/:id
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 68 def update @project = PlanMyStuff::Project.find(params[:id].to_i) @project.update!( title: project_params[:title], readme: project_params[:readme], description: project_params[:description], ) yield(@project) if block_given? return if performed? flash[:success] = 'Project was successfully updated.' redirect_to(plan_my_stuff.project_path(@project.number)) rescue PlanMyStuff::StaleObjectError => e pms_handle_rescue(e) flash.now[:error] = 'Project was modified by someone else. Please review the latest changes and try again.' render(:edit, status: PlanMyStuff.unprocessable_status) end |