Class: MechanizeStore::ProductsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/mechanize_store/products_controller.rb', line 28

def create
  @product = Product.new(product_params)

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

#destroyObject



58
59
60
61
62
63
64
# File 'app/controllers/mechanize_store/products_controller.rb', line 58

def destroy
  @product = Product.find(params[:id])
  
  flash[:alert] = I18n.t(:deleted, model: I18n.t(:product, scope: "activerecord.models")) if @product.destroy

  respond_with @product, :location => products_url
end

#editObject



24
25
26
# File 'app/controllers/mechanize_store/products_controller.rb', line 24

def edit
  respond_with @product
end

#indexObject



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

def index
  @search = Product.search(params[:q])

  @products = @search.result.paginate(page: params[:page])

  respond_with @products
end

#newObject



19
20
21
22
# File 'app/controllers/mechanize_store/products_controller.rb', line 19

def new
  @product = Product.new
  respond_with @product
end

#showObject



15
16
17
# File 'app/controllers/mechanize_store/products_controller.rb', line 15

def show
  respond_with @product
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/mechanize_store/products_controller.rb', line 43

def update
  @product = Product.find(params[:id])

  respond_with @product do |format|
    if @product.update(product_params)
      format.html do 
        flash[:notice] = I18n.t(:updated, model: I18n.t(:product, scope: "activerecord.models")) 
        redirect_to @product
      end
    else
      format.html { render action: "edit" }
    end
  end
end