Class: Admin::PhotosController

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

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/admin/photos_controller.rb', line 23

def create
  photo_file = photo_params[:photo]
  if photo_file.present?
    fingerprint = Digest::MD5.hexdigest(photo_file.read)
    photo_file.rewind
    @photo = SpudPhoto.where(photo_fingerprint: fingerprint).first
  end

  @photo = SpudPhoto.new(photo_params) if @photo.blank?

  if @photo.save
    success = true
    flash[:notice] = 'SpudPhoto created successfully'
  end
  if request.xhr?
    render json_for_photo(success)
  else
    respond_to_parent do
      render 'show.js'
    end
  end
end

#destroyObject



67
68
69
70
# File 'app/controllers/admin/photos_controller.rb', line 67

def destroy
  flash[:notice] = 'SpudPhoto deleted successfully' if @photo.destroy
  respond_with @photo, location: admin_photos_path
end

#editObject



46
47
48
49
50
# File 'app/controllers/admin/photos_controller.rb', line 46

def edit
  respond_with @photo do |format|
    format.js { render 'edit', layout: false }
  end
end

#indexObject



7
8
9
10
# File 'app/controllers/admin/photos_controller.rb', line 7

def index
  @photos = SpudPhoto.all
  respond_with @photos
end

#mass_destroyObject



72
73
74
75
76
# File 'app/controllers/admin/photos_controller.rb', line 72

def mass_destroy
  @photos = SpudPhoto.where(id: params[:spud_photo_ids])
  flash[:notice] = 'Photos deleted successfully' if @photos.destroy_all
  respond_with @photos, location: admin_photos_path
end

#newObject



16
17
18
19
20
21
# File 'app/controllers/admin/photos_controller.rb', line 16

def new
  @photo = SpudPhoto.new
  respond_with @photo do |format|
    format.js { render 'new', layout: false }
  end
end

#showObject



12
13
14
# File 'app/controllers/admin/photos_controller.rb', line 12

def show
  respond_with @photo
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/admin/photos_controller.rb', line 52

def update
  @photo.update_attributes(photo_params)
  if @photo.save
    success = true
    flash[:notice] = 'SpudPhoto updated successfully'
  end
  if request.xhr?
    render json_for_photo(success)
  else
    respond_to_parent do
      render 'show.js'
    end
  end
end