class UploadController

Public Instance Methods

audio() click to toggle source
# 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
avatar() click to toggle source
# 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
cover() click to toggle source
# 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

Protected Instance Methods

audio_params() click to toggle source
# File lib/generators/authkit/templates/app/controllers/upload_controller.rb, line 61
def audio_params
  params.require(:audio).permit(:attachment)
end
avatar_params() click to toggle source
# File lib/generators/authkit/templates/app/controllers/upload_controller.rb, line 69
def avatar_params
  params.require(:avatar).permit(:attachment, :remote_url)
end
aws_key_to_remote_url() click to toggle source
# File lib/generators/authkit/templates/app/controllers/upload_controller.rb, line 73
def aws_key_to_remote_url
  params[:avatar] ||= {}
  params[:avatar][:remote_url] ||= view_context.aws_url_for(params[:key]) if params[:key].present?
end
cover_params() click to toggle source
# File lib/generators/authkit/templates/app/controllers/upload_controller.rb, line 65
def cover_params
  params.require(:cover).permit(:attachment)
end