tap/app/controllers/barcodes_controller.rb

45 lines
950 B
Ruby
Raw Normal View History

2016-03-08 15:53:50 +01:00
# == Schema Information
#
# Table name: barcodes
#
# id :integer not null, primary key
# product_id :integer
# code :string default(""), not null
# created_at :datetime
# updated_at :datetime
#
class BarcodesController < ApplicationController
2015-10-07 16:39:06 +02:00
load_and_authorize_resource :product, only: :create
2015-10-27 22:09:01 +01:00
load_and_authorize_resource :barcode, through: :product, shallow: true
2015-10-28 21:54:55 +01:00
def create
@barcode.save
2015-09-26 11:57:41 +02:00
redirect_to barcode_products_path, notice: "Barcode successfully linked!"
end
2015-10-27 22:09:01 +01:00
def index
@barcodes = Barcode.all.order(:code)
2019-04-20 15:36:23 +02:00
respond_to do |format|
format.json {render json: @barcodes}
format.html {}
end
2015-10-27 22:09:01 +01:00
end
def show
2015-10-07 16:42:05 +02:00
@barcode = Barcode.find_by(code: params[:id])
2015-10-07 16:49:29 +02:00
render json: @barcode.try(:product)
end
2015-10-27 22:09:01 +01:00
def destroy
@barcode.destroy
redirect_to barcodes_path
end
private
def barcode_params
params.require(:barcode).permit(:code)
end
end