Files
mozo-backend/app/controllers/admin/suppliers_controller.rb
T

107 lines
2.8 KiB
Ruby

module Admin
class SuppliersController < Admin::ApplicationController
before_filter :set_relation_options, only: [:new, :edit, :create, :update]
skip_before_filter :authenticate_administrator!, only: :test_login
skip_before_filter :set_locale, only: :test_login
# GET /suppliers
# GET /suppliers.json
def index
@suppliers = Supplier.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @suppliers }
end
end
def test_login
if Rails.env.test? and supplier = Supplier.find_by_email(params[:email])
sign_in supplier
end
render nothing: true
end
# GET /suppliers/1
# GET /suppliers/1.json
def show
@supplier = Supplier.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @supplier }
end
end
# GET /suppliers/new
# GET /suppliers/new.json
def new
@supplier = Supplier.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @supplier }
end
end
# GET /suppliers/1/edit
def edit
@supplier = Supplier.find(params[:id])
end
# POST /suppliers
# POST /suppliers.json
def create
@supplier = Supplier.new(supplier_params)
respond_to do |format|
if @supplier.save
format.html { redirect_to [:admin, @supplier], notice: t('action.create.successfull', model: Supplier.model_name.human) }
format.json { render json: @supplier, status: :created, location: @supplier }
else
format.html { render action: "new" }
format.json { render json: @supplier.errors, status: :unprocessable_entity }
end
end
end
# PUT /suppliers/1
# PUT /suppliers/1.json
def update
@supplier = Supplier.find(params[:id])
respond_to do |format|
if @supplier.update_attributes(supplier_params)
format.html { redirect_to [:admin, @supplier], notice: t('action.update.successfull', model: Supplier.model_name.human) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @supplier.errors, status: :unprocessable_entity }
end
end
end
# DELETE /suppliers/1
# DELETE /suppliers/1.json
def destroy
@supplier = Supplier.find(params[:id])
@supplier.destroy
respond_to do |format|
format.html { redirect_to admin_suppliers_path, notice: t('action.destroy.successfull', model: Supplier.model_name.human) }
format.json { head :no_content }
end
end
private
def set_relation_options
@suppliers = Supplier.all
@lists = List.all
end
def supplier_params
params.require(:supplier).permit!
end
end
end