Class: M::Icol::CustomersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- M::Icol::CustomersController
- Includes:
- Approval2::ControllerAdditions
- Defined in:
- app/controllers/m/icol/customers_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
- #audit_logs ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#approve ⇒ Object
56 57 58 |
# File 'app/controllers/m/icol/customers_controller.rb', line 56 def approve redirect_to unapproved_records_path(group_name: 'icol') end |
#audit_logs ⇒ Object
51 52 53 54 |
# File 'app/controllers/m/icol/customers_controller.rb', line 51 def audit_logs @record = Customer.unscoped.find(params[:id]) rescue nil @audit = @record.audits[params[:version_id].to_i] rescue nil end |
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/m/icol/customers_controller.rb', line 12 def create @customer = Customer.new(params[:customer]) if !@customer.valid? render "new" else @customer.created_by = current_user.id @customer.save! flash[:alert] = 'Customer successfully created and is pending for approval' redirect_to @customer end end |
#index ⇒ Object
45 46 47 48 49 |
# File 'app/controllers/m/icol/customers_controller.rb', line 45 def index customers = (params[:approval_status].present? and params[:approval_status] == 'U') ? Customer.unscoped.where("approval_status =?",'U').order("id desc") : Customer.order("id desc") @customers_count = customers.count @customers = customers.paginate(:per_page => 10, :page => params[:page]) rescue [] end |
#new ⇒ Object
8 9 10 |
# File 'app/controllers/m/icol/customers_controller.rb', line 8 def new @customer = Customer.new end |
#show ⇒ Object
41 42 43 |
# File 'app/controllers/m/icol/customers_controller.rb', line 41 def show @customer = Customer.unscoped.find_by_id(params[:id]) end |
#update ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/m/icol/customers_controller.rb', line 24 def update @customer = Customer.unscoped.find_by_id(params[:id]) @customer.attributes = params[:customer] if !@customer.valid? render "edit" else @customer.updated_by = current_user.id @customer.save! flash[:alert] = 'Customer successfully modified successfully' redirect_to @customer end rescue ActiveRecord::StaleObjectError @customer.reload flash[:alert] = 'Someone edited the customer the same time you did. Please re-apply your changes to the customer.' render "edit" end |