2015-09-25 12:24:32 +00:00
|
|
|
class BarcodesController < ApplicationController
|
2015-10-07 14:39:06 +00:00
|
|
|
load_and_authorize_resource :product, only: :create
|
2015-10-27 21:09:01 +00:00
|
|
|
load_and_authorize_resource :barcode, through: :product, shallow: true
|
2015-10-28 20:54:55 +00:00
|
|
|
|
2015-09-25 12:24:32 +00:00
|
|
|
def create
|
|
|
|
@barcode.save
|
2015-09-26 09:57:41 +00:00
|
|
|
redirect_to barcode_products_path, notice: "Barcode successfully linked!"
|
2015-09-25 12:24:32 +00:00
|
|
|
end
|
|
|
|
|
2015-10-27 21:09:01 +00:00
|
|
|
def index
|
|
|
|
@barcodes = Barcode.all.order(:code)
|
|
|
|
end
|
|
|
|
|
2015-09-28 19:51:40 +00:00
|
|
|
def show
|
2015-10-07 14:42:05 +00:00
|
|
|
@barcode = Barcode.find_by(code: params[:id])
|
2015-10-07 14:49:29 +00:00
|
|
|
render json: @barcode.try(:product)
|
2015-09-28 19:51:40 +00:00
|
|
|
end
|
|
|
|
|
2015-10-27 21:09:01 +00:00
|
|
|
def destroy
|
|
|
|
@barcode.destroy
|
|
|
|
redirect_to barcodes_path
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:24:32 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def barcode_params
|
|
|
|
params.require(:barcode).permit(:code)
|
|
|
|
end
|
|
|
|
end
|