Class: UploadController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/authkit/templates/app/controllers/upload_controller.rb

Instance Method Summary collapse

Instance Method Details

#audioObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/authkit/templates/app/controllers/upload_controller.rb', line 8

def audio
  @audio = current_user.audios.build(audio_params)

  # Each new upload needs to be unique in case the same file is uploaded twice with different content
  @audio.attachment_uploaded_at = Time.now

  if @audio.save
    respond_to do |format|
      format.json { render json: @audio }
    end
  else
    respond_to do |format|
      format.json { render json: { status: 'error', errors: @audio.errors }.to_json, status: 422 }
    end
  end
end

#avatarObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/authkit/templates/app/controllers/upload_controller.rb', line 42

def avatar
  @avatar = current_user.build_avatar(avatar_params)

  # Each new upload needs to be unique in case the same file is uploaded twice with different content
  @avatar.attachment_uploaded_at = Time.now

  if current_user.save
    respond_to do |format|
      format.json { render json: @avatar }
    end
  else
    respond_to do |format|
      format.json { render json: { status: 'error', errors: @avatar.errors }.to_json, status: 422 }
    end
  end
end

#coverObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/authkit/templates/app/controllers/upload_controller.rb', line 25

def cover
  @cover = current_user.covers.build(cover_params)

  # Each new upload needs to be unique in case the same file is uploaded twice with different content
  @cover.attachment_uploaded_at = Time.now

  if @cover.save
    respond_to do |format|
      format.json { render json: @cover }
    end
  else
    respond_to do |format|
      format.json { render json: { status: 'error', errors: @cover.errors }.to_json, status: 422 }
    end
  end
end