app/controllers/admin/photos_controller.rb in tb_photos-1.0.6 vs app/controllers/admin/photos_controller.rb in tb_photos-1.1.0.beta1

- old
+ new

@@ -1,8 +1,9 @@ class Admin::PhotosController < Admin::ApplicationController include RespondsToParent + belongs_to_spud_app :photo_albums before_filter :get_photo, :only => [:show, :edit, :update, :destroy] layout false def index @@ -20,10 +21,20 @@ format.js { render 'new', :layout => false } end end def create - @photo = SpudPhoto.new(photo_params) + 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 + + if @photo.blank? + @photo = SpudPhoto.new(photo_params) + end + if @photo.save success = true flash[:notice] = 'SpudPhoto created successfully' end if request.xhr?