Last active
August 29, 2015 14:22
-
-
Save fabrinal/d51dd878bacf369bef6f to your computer and use it in GitHub Desktop.
Private scope part of photo_galleries_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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