Skip to content

Instantly share code, notes, and snippets.

@fabrinal
Last active August 29, 2015 14:22
Show Gist options
  • Save fabrinal/d51dd878bacf369bef6f to your computer and use it in GitHub Desktop.
Save fabrinal/d51dd878bacf369bef6f to your computer and use it in GitHub Desktop.
Private scope part of photo_galleries_controller.rb
private
# Use callbacks to share common setup or constraints between actions.
def set_photo_gallery
@photo_gallery = PhotoGallery.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def photo_gallery_params
# add :photos param below
params.require(:photo_gallery).permit(:description,:photos)
end
# new method added below
def save_photos images
if images
images.each_value { |image|
@photo_gallery.photos.create(image: image)
}
end
end
def compare_photos images
if images.presence
images.each { |key,new_image|
if @photo_gallery.photos[key.to_i].presence
@photo_gallery.photos[key.to_i].image = new_image
@photo_gallery.photos[key.to_i].save
else
@photo_gallery.photos.create(image: new_image)
end
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment