Sha256: 088c698a43bce9372ae9ab15f8d9f577118d7bd4a863410aea2a9029e28e69f1

Contents?: true

Size: 1.49 KB

Versions: 17

Compression:

Stored size: 1.49 KB

Contents

require_dependency "mechanize_store/application_controller"

module MechanizeStore
    class ProductPhotosController < ApplicationController
        respond_to :html, :json

        def index
            @product = Product.find(params[:product_id])
            
            @product_photos = @product.product_photos

            respond_with @product_photos
        end
        
        def create
            @product_photos = []

            @product = Product.find(params[:product_id])

            @product_photo = @product.product_photos.new(file: params["product_photo"]["file"][0])
        
            respond_with @product_photo do |format|
                if @product_photo.save
                    @product_photos << @product_photo
                    format.html { redirect_to @product, notice: I18n.t(:created, model: I18n.t(:product_photo, scope: 'activerecord.models')) }
                else
                    format.html { render action: 'new' }
                end
            end
        end 

        def destroy
            @product_photo = ProductPhoto.find(params[:id])
            @product = @product_photo.product                        
            @product_photo.destroy

            respond_with @product_photo do |format| 
                format.html do 
                    redirect_to @product
                end
            end
        end 

        private
        def product_photo_params
            params.require(:product_photo).permit(:product_id, file: [])
        end
    end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
mechanize_store-0.0.19 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.18 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.17 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.16 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.15 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.14 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.13 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.12 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.11 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.10 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.8 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.7 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.6 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.5 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.4 app/controllers/mechanize_store/product_photos_controller.rb
mechanize_store-0.0.3 app/controllers/mechanize_store/product_photos_controller.rb
mechanize-store-0.0.2 app/controllers/mechanize_store/product_photos_controller.rb