Class: Admin::BaitLibraries::BaitLibrarySuppliersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb

Overview

Add and edit BaitLibrary::Suppliers

Instance Method Summary collapse

Instance Method Details

#createObject


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb', line 13

def create
  @bait_library_supplier = BaitLibrary::Supplier.new(bait_library_supplier_params)

  respond_to do |format|
    if @bait_library_supplier.save
      flash[:notice] = 'Supplier was successfully created.'
      format.html { redirect_to(admin_bait_libraries_path) }
    else
      format.html { render action: 'new' }
    end
  end
end

#destroyObject


37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb', line 37

def destroy
  usage_count = @bait_library_supplier.bait_libraries.visible.count
  if usage_count > 0
    name = @bait_library_supplier.name
    flash[:error] = "Can not delete '#{name}', supplier is in use by #{usage_count} libraries."
  else
    @bait_library_supplier.hide
    flash[:notice] = 'Supplier was successfully deleted.'
  end

  redirect_to(admin_bait_libraries_path)
end

#editObject


11
# File 'app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb', line 11

def edit; end

#newObject


7
8
9
# File 'app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb', line 7

def new
  @bait_library_supplier = BaitLibrary::Supplier.new
end

#updateObject


26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/bait_libraries/bait_library_suppliers_controller.rb', line 26

def update
  respond_to do |format|
    if @bait_library_supplier.update(bait_library_supplier_params)
      flash[:notice] = 'Supplier was successfully updated.'
      format.html { redirect_to(admin_bait_libraries_path) }
    else
      format.html { render action: 'edit' }
    end
  end
end