Class: Admin::BaitLibraries::BaitLibraryTypesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @bait_library_type = BaitLibraryType.new(params[:bait_library_type])

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

#destroyObject



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

def destroy
  usage_count = @bait_library_type.bait_libraries.visible.count
  if usage_count > 0
    name = @bait_library_type.name
    flash[:error] = "Can not delete '#{name}', bait library type is in use by #{usage_count} libraries."
  else
    @bait_library_type.hide
    flash[:notice] = 'Bait Library Type was successfully deleted.'
  end

  redirect_to(admin_bait_libraries_path)
end

#editObject



12
13
# File 'app/controllers/admin/bait_libraries/bait_library_types_controller.rb', line 12

def edit
end

#newObject



8
9
10
# File 'app/controllers/admin/bait_libraries/bait_library_types_controller.rb', line 8

def new
  @bait_library_type = BaitLibraryType.new
end

#updateObject



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

def update
  respond_to do |format|
    if @bait_library_type.update(params[:bait_library_type])
      flash[:notice] = 'Bait Library Type was successfully updated.'
      format.html { redirect_to(admin_bait_libraries_path) }
    else
      format.html { render action: 'edit' }
    end
  end
end