Class: Shoppy::BrandsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shoppy/brands_controller.rb

Direct Known Subclasses

BrandsController

Instance Method Summary collapse

Instance Method Details

#deleteObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/shoppy/brands_controller.rb', line 43

def delete
  @brand = Brand.find_by(id: params[:brand_id])
  if @brand
    @brand.destroy
    Log.newEvent("Brands", "Brand named '#{@brand.name}' was deleted", current_admin.name)
    flash[:notice] = "Brand has been deleted."
    redirect_to '/products/brands'
  else
    page_not_found
  end
end

#editObject



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/shoppy/brands_controller.rb', line 31

def edit
  @brand = Brand.find_by(id: params[:brand_id])
  if @brand
    @brand.update_attributes(brand_params)
    Log.newEvent("Brands", "Brand named '#{@brand.name}' was updated", current_admin.name)
    redirect_to '/products/brands/' + @brand.id.to_s
    flash[:notice] = "Brand has been updated."
  else
    page_not_found
  end
end

#indexObject



5
6
7
8
# File 'app/controllers/shoppy/brands_controller.rb', line 5

def index
  @brands = Brand.all
  @brand = Brand.new
end

#newObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/shoppy/brands_controller.rb', line 10

def new
  @brand = Brand.new(brand_params)
  @brand.name = @brand.name
  if @brand.save
    Log.newEvent("Brands", "New brand named '#{@brand.name}' was created", current_admin.name)
    flash[:notice] = "Brand has been created."
  else
    flash[:error] = @brand.errors.messages
  end
  redirect_to '/products/brands'
end

#showObject



22
23
24
25
26
27
28
29
# File 'app/controllers/shoppy/brands_controller.rb', line 22

def show
  b = Brand.find_by(id: params[:brand_id])
  if b
    @brand = b
  else
    page_not_found
  end
end