Class: MechanizeStore::ProductPhotosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mechanize_store/product_photos_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/mechanize_store/product_photos_controller.rb', line 15

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

#destroyObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/mechanize_store/product_photos_controller.rb', line 32

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

#indexObject



7
8
9
10
11
12
13
# File 'app/controllers/mechanize_store/product_photos_controller.rb', line 7

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

    respond_with @product_photos
end