SHARE
TWEET

Untitled

a guest May 27th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ProjectsController < ApplicationController
  2.   load_and_authorize_resource
  3.   before_action :set_project, only: [:show, :edit, :update, :destroy]
  4.   before_action :set_variables, only: :edit
  5.  
  6.   def index
  7.     @projects = Project.includes(:subprojects).where(parent_id: nil)
  8.   end
  9.  
  10.   def show; end
  11.  
  12.   def new
  13.     @project = Project.new
  14.     set_variables
  15.   end
  16.  
  17.   def edit; end
  18.  
  19.   def create
  20.     @project = Project.new(project_params)
  21.     if @project.save
  22.       redirect_to projects_path, notice: 'Project was successfully created.'
  23.     else
  24.       set_variables
  25.       render :new
  26.     end
  27.   end
  28.  
  29.   def update
  30.     if @project.update(project_params)
  31.       redirect_to projects_path, notice: 'Project was successfully updated.'
  32.     else
  33.       set_variables
  34.       render :edit
  35.     end
  36.   end
  37.  
  38.   def destroy
  39.     @project.destroy
  40.     redirect_to projects_url, notice: 'Project was successfully deleted.'
  41.   end
  42.  
  43.   private
  44.  
  45.   def set_variables
  46.     @customers = Customer.all
  47.     @users = User.all
  48.     @categories = Category.order(:name)
  49.   end
  50.  
  51.   def set_project
  52.     @project = Project.find(params[:id])
  53.   end
  54.  
  55.   def project_params
  56.     params.require(:project).permit(:name, :description, :time, :fixed_price, :customer_id, :lead_id, :parent_id, category_ids: [],
  57.       user_ids: [], categories_projects_attributes: [:id, :external_rate, :category_id, :_destroy], subprojects_attributes: [:id, :name, :description, :time, :fixed_price,
  58.       :customer_id, :lead_id, :parent_id, category_ids: [], user_ids: [], categories_projects_attributes: [:id, :external_rate, :category_id, :_destroy]])
  59.   end
  60. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top