Class: GalleryController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- GalleryController
- Defined in:
- app/controllers/gallery_controller.rb
Instance Method Summary collapse
- #add_to_gallery ⇒ Object
-
#create ⇒ Object
POST /gallery.
-
#destroy ⇒ Object
DELETE /gallery/1.
- #index ⇒ Object
- #manage ⇒ Object
-
#new ⇒ Object
GET /gallery/new.
- #remove_from_gallery ⇒ Object
- #remove_gallery ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
PATCH/PUT /gallery/1.
- #upload_to_gallery ⇒ Object
Instance Method Details
#add_to_gallery ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/gallery_controller.rb', line 19 def add_to_gallery if !params[:id] redirect_back(fallback_location: admin_gallery_path) and return end ap "adding pfiSet: #{params[:id]} to gallery images" gallery = Gallery.first ### get pfiSet and copy to giSet pfiSet = PortfolioImage.find(params[:id]) giSet = GalleryImage.where(gallery_id: gallery.id, portfolio_images_id: pfiSet.id).first_or_create giSet.before.attach(io: StringIO.new(pfiSet.before.download), filename: pfiSet.before.filename, content_type: pfiSet.before.content_type) giSet.after.attach(io: StringIO.new(pfiSet.after.download), filename: pfiSet.after.filename, content_type: pfiSet.after.content_type) giSet.caption = pfiSet.portfolio.user.first_name + " " + pfiSet.portfolio.user.last_name + " | " + pfiSet.portfolio.user.city + ", " + pfiSet.portfolio.user.state giSet.portfolio_images_id = pfiSet.id giSet.save end |
#create ⇒ Object
POST /gallery
91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/gallery_controller.rb', line 91 def create @gallery = Gallery.new(gallery_params) if @gallery.save redirect_to @gallery, notice: 'Gallery was successfully created.' else render :new end end |
#destroy ⇒ Object
DELETE /gallery/1
111 112 113 114 |
# File 'app/controllers/gallery_controller.rb', line 111 def destroy @gallery.destroy redirect_to gallery_url, notice: 'Gallery was successfully destroyed.' end |
#index ⇒ Object
4 5 6 7 |
# File 'app/controllers/gallery_controller.rb', line 4 def index @page = 'gallery' @galleries = Gallery.all end |
#manage ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/gallery_controller.rb', line 9 def manage @page = 'manage' if params[:id] @gallery = Gallery.find(params[:id]) else redirect_to gallery_path and return end end |
#new ⇒ Object
GET /gallery/new
86 87 88 |
# File 'app/controllers/gallery_controller.rb', line 86 def new @gallery = Gallery.new end |
#remove_from_gallery ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/controllers/gallery_controller.rb', line 72 def remove_from_gallery if !params[:id] redirect_back(fallback_location: gallery_path) and return end rmImage = GalleryImage.find(params[:id]) rmImage.destroy end |
#remove_gallery ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/controllers/gallery_controller.rb', line 63 def remove_gallery if !params[:id] redirect_to gallery_path and return end gallery = Gallery.find(params[:id]) gallery.destroy end |
#show ⇒ Object
81 82 83 |
# File 'app/controllers/gallery_controller.rb', line 81 def show end |
#update ⇒ Object
PATCH/PUT /gallery/1
102 103 104 105 106 107 108 |
# File 'app/controllers/gallery_controller.rb', line 102 def update if @gallery.update(gallery_params) redirect_to @gallery, notice: 'Gallery was successfully updated.' else render :edit end end |
#upload_to_gallery ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/gallery_controller.rb', line 38 def upload_to_gallery ### do we have uploaded portfolio images if params[:image] && params[:gallery_id] image = params[:image] caption = params[:caption] gallery = Gallery.find(params[:gallery_id]) gImage = GalleryImage.new gImage.gallery_id = gallery.id gImage.image.attach(io: File.open(image.path), filename: image.original_filename, content_type: image.content_type) gImage.caption = (caption.blank?)? " " : caption gImage.save flash[:success] = "Image was successfully added to the gallery" redirect_back(fallback_location: gallery_path) and return else flash[:error] = "Something went wrong... what did you do?!" redirect_back(fallback_location: gallery_path) and return end end |