Files
mozo-backend/app/controllers/suppliers/tables_controller.rb
T
2013-01-10 01:00:59 +01:00

95 lines
2.6 KiB
Ruby

module Suppliers
class TablesController < Suppliers::ApplicationController
# GET /tables
# GET /tables.json
def index
@tables = current_supplier.tables
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tables }
end
end
# GET /tables/1
# GET /tables/1.json
def show
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @table }
end
end
# GET /tables/new
# GET /tables/new.json
def new
@table = Table.new
@table.section_id = params[:section_id].presence
respond_to do |format|
format.html # new.html.erb
format.json { render json: @table }
end
end
# GET /tables/1/edit
def edit
@table = Table.find(params[:id])
end
# POST /tables
# POST /tables.json
def create
@table = Table.new(params[:table])
@table.supplier = current_supplier
respond_to do |format|
if @table.save
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.create.successfull', model: Table.model_name.human) }
format.json { render json: @table, status: :created, location: @table }
else
format.html { render action: "new" }
format.json { render json: @table.errors, status: :unprocessable_entity }
end
end
end
# PUT /tables/1
# PUT /tables/1.json
def update
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format|
if @table.update_attributes(params[:table])
format.html { redirect_to [:suppliers, @table], notice: t('action.update.successfull', model: Table.model_name.human) }
format.json { head :no_content }
format.js { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @table.errors, status: :unprocessable_entity }
format.js { head :no_content }
end
end
end
# DELETE /tables/1
# DELETE /tables/1.json
def destroy
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@table.destroy
respond_to do |format|
format.html { redirect_to suppliers_tables_url, notice: t('action.destroy.successfull', model: Table.model_name.human) }
format.json { head :no_content }
end
end
def qr_codes
@tables = current_supplier.tables
render layout: 'qr_sheet'
end
end
end