Class: Adminpanel::ProductsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Adminpanel::ProductsController
- Defined in:
- app/controllers/adminpanel/products_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/products POST /admin/products.json.
-
#destroy ⇒ Object
DELETE /admin/products/1 DELETE /admin/products/1.json.
-
#edit ⇒ Object
GET /admin/products/1/edit.
-
#index ⇒ Object
GET /admin/products GET /admin/products.json.
-
#new ⇒ Object
GET /admin/products/new GET /admin/products/new.json.
-
#show ⇒ Object
GET /admin/products/1 GET /admin/products/1.json.
-
#update ⇒ Object
PUT /admin/products/1 PUT /admin/products/1.json.
Methods inherited from ApplicationController
#handle_unverified_request, #signed_in_user
Methods included from SessionsHelper
#current_user, #current_user=, #sign_in, #sign_out, #signed_in?
Instance Method Details
#create ⇒ Object
POST /admin/products POST /admin/products.json
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/adminpanel/products_controller.rb', line 45 def create @product = Product.new(params[:product]) respond_to do |format| if @product.save format.html { redirect_to product_path(@product), :notice => 'Product was successfully created.' } format.json { render :json => product_path(@product), :status => :created, :location => @product } else @categories = Category.all.collect{|c| [ c.name, c.id ] } format.html { render :action => "new" } format.json { render :json => @product.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /admin/products/1 DELETE /admin/products/1.json
78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/adminpanel/products_controller.rb', line 78 def destroy @product = Product.find(params[:id]) @product.destroy respond_to do |format| format.html { redirect_to products_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /admin/products/1/edit
38 39 40 41 |
# File 'app/controllers/adminpanel/products_controller.rb', line 38 def edit @product = Product.find(params[:id]) @categories = Category.all.collect{|c| [ c.name, c.id ] } end |
#index ⇒ Object
GET /admin/products GET /admin/products.json
5 6 7 8 9 10 11 12 |
# File 'app/controllers/adminpanel/products_controller.rb', line 5 def index @products = Product.all respond_to do |format| format.html # index.html.erb format.json { render :json => @products } end end |
#new ⇒ Object
GET /admin/products/new GET /admin/products/new.json
27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/adminpanel/products_controller.rb', line 27 def new @product = Product.new @categories = Category.all.collect{|c| [ c.name, c.id ] } respond_to do |format| format.html # new.html.erb format.json { render :json => @product } end end |
#show ⇒ Object
GET /admin/products/1 GET /admin/products/1.json
16 17 18 19 20 21 22 23 |
# File 'app/controllers/adminpanel/products_controller.rb', line 16 def show @product = Product.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render :json => @product } end end |
#update ⇒ Object
PUT /admin/products/1 PUT /admin/products/1.json
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/adminpanel/products_controller.rb', line 62 def update @product = Product.find(params[:id]) respond_to do |format| if @product.update_attributes(params[:product]) format.html { redirect_to product_path(@product), :notice => 'Product was successfully updated.' } format.json { head :no_content } else format.html { render :action => "edit" } format.json { render :json => @product.errors, :status => :unprocessable_entity } end end end |