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



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

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



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

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
12
# 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



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

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