Skip to content

Commit

Permalink
minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwachajr committed May 28, 2019
1 parent 357db6e commit b8a08c9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def destroy
# POST /moments/1/picture
# POST /moments/1/picture.json
def picture
moment = set_moment(params[:moment_id])
cloudinary_response = CloudinaryService.upload(file, 'options')
# to do: add image upload options
cloudinary_response = CloudinaryService.upload(file, options)

return if cloudinary_response.nil?

moment = set_moment(params[:moment_id])
moment.picture_id = cloudinary_response['public_id']
moment.save!
end
Expand All @@ -92,7 +93,7 @@ def set_moment

def moment_params
params.require(:moment).permit(
:name, :why, :fix, :comment, :published_at, :draft, :image,
:name, :why, :fix, :comment, :published_at, :draft,
category: [], mood: [], viewers: [], strategy: []
)
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/moment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Moment < ApplicationRecord
include CommonMethods
extend FriendlyId

mount_uploader :image, AvatarUploader

friendly_id :name
serialize :category, Array
serialize :viewers, Array
Expand Down
6 changes: 4 additions & 2 deletions app/services/cloudinary_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
class CloudinaryService
class << self
def upload(file, options = {})
# to do: add exception handling
Cloudinary::Uploader.upload(file, options)
rescue StandardError
nil
end

def delete(public_id, options = {})
# to do: add exception handling
Cloudinary::Uploader.destroy(public_id, options)
rescue StandardError
nil
end
end
end
2 changes: 1 addition & 1 deletion spec/services/cloudinary_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
FILENAME = "moment.jpeg"
FILE_PATH = "/public/uploads/tmp/moment"
FILE_PATH = "/spec/uploads/"
OPTIONS = {}

describe CloudinaryService do
Expand Down
File renamed without changes

0 comments on commit b8a08c9

Please sign in to comment.