Reduced percieved complexity in photos_controller.rb

This commit is contained in:
Brenda Wallace
2016-11-19 22:28:38 +13:00
parent b3ae03ab7e
commit 9c4f011fbc
2 changed files with 10 additions and 6 deletions

View File

@@ -45,4 +45,4 @@ Metrics/LineLength:
# Offense count: 8
Metrics/PerceivedComplexity:
Max: 12
Max: 11

View File

@@ -47,11 +47,7 @@ class PhotosController < ApplicationController
# POST /photos
# POST /photos.json
def create
@photo = Photo.find_by_flickr_photo_id(params[:photo][:flickr_photo_id]) ||
Photo.new(photo_params)
@photo.owner_id = current_member.id
@photo.set_flickr_metadata
@photo = find_or_create_from_flickr_photo params[:photo][:flickr_photo_id]
collection = case params[:type]
when 'garden'
@@ -129,4 +125,12 @@ class PhotosController < ApplicationController
params.require(:photo).permit(:flickr_photo_id, :owner_id, :title, :license_name,
:license_url, :thumbnail_url, :fullsize_url, :link_url)
end
def find_or_create_from_flickr_photo(flickr_photo_id)
photo = Photo.find_by(flickr_photo_id: flickr_photo_id)
photo = Photo.new(photo_params) unless photo
photo.owner_id = current_member.id
photo.set_flickr_metadata
photo
end
end