Class: PlanMyStuff::ProjectsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- PlanMyStuff::ProjectsController
- Defined in:
- app/controllers/plan_my_stuff/projects_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /projects.
-
#edit ⇒ Object
GET /projects/:id/edit.
-
#index ⇒ Object
GET /projects.
-
#new ⇒ Object
GET /projects/new.
-
#show ⇒ Object
GET /projects/:id.
-
#update ⇒ Object
PATCH/PUT /projects/:id.
Instance Method Details
#create ⇒ Object
POST /projects
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 23 def create @project = PlanMyStuff::Project.create!( title: project_params[:title], readme: project_params[:readme] || '', description: project_params[:description], user: pms_current_user, ) 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 ⇒ Object
GET /projects/:id/edit
52 53 54 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 52 def edit @project = PlanMyStuff::Project.find(params[:id].to_i) end |
#index ⇒ Object
GET /projects
6 7 8 9 10 11 12 13 14 15 |
# 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 end |
#new ⇒ Object
GET /projects/new
18 19 20 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 18 def new @project = PlanMyStuff::Project.new end |
#show ⇒ Object
GET /projects/:id
45 46 47 48 49 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 45 def show @project = PlanMyStuff::Project.find(params[:id].to_i) @statuses = @project.statuses.pluck(:name) @items_by_status = @project.items.group_by(&:status) end |
#update ⇒ Object
PATCH/PUT /projects/:id
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 57 def update @project = PlanMyStuff::Project.find(params[:id].to_i) @project.update!( title: project_params[:title], readme: project_params[:readme], description: project_params[:description], ) 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 |