Add barcodes index and destroy
This commit is contained in:
parent
80899f21aa
commit
6b3e57ab45
5 changed files with 30 additions and 3 deletions
|
@ -1,17 +1,25 @@
|
|||
class BarcodesController < ApplicationController
|
||||
load_and_authorize_resource :product, only: :create
|
||||
load_and_authorize_resource :barcode, through: :product, only: :create
|
||||
|
||||
load_and_authorize_resource :barcode, through: :product, shallow: true
|
||||
def create
|
||||
@barcode.save
|
||||
redirect_to barcode_products_path, notice: "Barcode successfully linked!"
|
||||
end
|
||||
|
||||
def index
|
||||
@barcodes = Barcode.all.order(:code)
|
||||
end
|
||||
|
||||
def show
|
||||
@barcode = Barcode.find_by(code: params[:id])
|
||||
render json: @barcode.try(:product)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@barcode.destroy
|
||||
redirect_to barcodes_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def barcode_params
|
||||
|
|
6
app/views/barcodes/_barcode.html.haml
Normal file
6
app/views/barcodes/_barcode.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%tr
|
||||
%td= barcode.id
|
||||
%td= barcode.code
|
||||
%td= barcode.product.name
|
||||
%td= image_tag barcode.product.avatar(:small)
|
||||
%td= button_to "Delete", barcode_path(barcode), method: :delete, class: "btn btn-danger"
|
10
app/views/barcodes/index.html.haml
Normal file
10
app/views/barcodes/index.html.haml
Normal file
|
@ -0,0 +1,10 @@
|
|||
.row
|
||||
.col-md-8.col-md-offset-2
|
||||
%table.table.table-striped
|
||||
%tr
|
||||
%th
|
||||
%th Barcode
|
||||
%th Product
|
||||
%th
|
||||
%th
|
||||
= render @barcodes
|
|
@ -23,6 +23,7 @@
|
|||
%ul.dropdown-menu{role: "menu"}
|
||||
%li= link_to "List", products_path
|
||||
%li= link_to "Add product" , barcode_products_path
|
||||
%li= link_to "Barcodes", barcodes_path
|
||||
%li.dropdown
|
||||
%a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"}
|
||||
Logged in as #{current_user.name}
|
||||
|
|
|
@ -26,12 +26,14 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :products, only: [:create, :index, :edit, :update] do
|
||||
resources :barcodes, only: [:create, :show], shallow: true
|
||||
resources :barcodes, only: :create
|
||||
collection do
|
||||
get 'barcode' => 'products#barcode', as: :barcode
|
||||
post 'barcode' => 'products#load_barcode', as: :load_barcode
|
||||
end
|
||||
end
|
||||
|
||||
resources :barcodes, only: [:show, :index, :destroy]
|
||||
|
||||
get 'overview' => 'orders#overview', as: "orders"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue