Class: Spina::Shop::Admin::CustomersController
- Inherits:
-
AdminController
- Object
- Admin::AdminController
- AdminController
- Spina::Shop::Admin::CustomersController
- Defined in:
- app/controllers/spina/shop/admin/customers_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #validate_vat_id ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 17 def create @customer = Customer.new(customer_params) if @customer.save redirect_to spina.shop_admin_customer_path(@customer) else render :new end end |
#edit ⇒ Object
31 32 33 34 35 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 31 def edit @customer = Customer.find(params[:id]) @customer.name, spina.shop_admin_customer_path(@customer) t('spina.edit') end |
#index ⇒ Object
6 7 8 9 10 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 6 def index @q = Customer.ransack(params[:q]) @customers = @q.result.sorted.page(params[:page]).per(25) @customer_groups = CustomerGroup.all end |
#new ⇒ Object
12 13 14 15 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 12 def new @customer = Customer.new t('spina.shop.customers.new') end |
#show ⇒ Object
26 27 28 29 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 26 def show @customer = Customer.find(params[:id]) @customer.name end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 37 def update @customer = Customer.find(params[:id]) if @customer.update_attributes(customer_params) redirect_to spina.shop_admin_customer_path(@customer) else t('spina.edit') render :edit end end |
#validate_vat_id ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/controllers/spina/shop/admin/customers_controller.rb', line 47 def validate_vat_id @customer = Customer.find(params[:id]) if vat_details = Valvat.new(@customer.vat_id).exists?(detail: true) render json: {valid: true, details: vat_details} else render json: {valid: false} end end |