Class: Spree::Admin::SolidusTiny::AccountsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::SolidusTiny::AccountsController
- Defined in:
- app/controllers/spree/admin/solidus_tiny/accounts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #upsert_sellers ⇒ Object
Instance Method Details
#create ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 28 def create tiny_account = ::SolidusTiny::Account.new account_params if tiny_account.save flash[:success] = "Conta criada com sucesso" redirect_to admin_solidus_tiny_accounts_path else flash[:error] = tiny_account.errors..join("\n") redirect_to new_admin_solidus_tiny_account_path end end |
#destroy ⇒ Object
51 52 53 54 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 51 def destroy @tiny_account.delete redirect_to admin_solidus_tiny_accounts_path end |
#edit ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 39 def edit @payment_methods = ::Spree::PaymentMethod.all.pluck(:name, :id) @shipping_methods = ::Spree::ShippingMethod.all.pluck(:name, :id) @sellers = @tiny_account.sellers.actives.order(:name).pluck(:name, :id) end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 7 def index @accounts = ::SolidusTiny::Account.all end |
#new ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 15 def new if ::SolidusTiny::Account.any? flash[:error] = "Você só pode ter uma conta Tiny cadastrada" redirect_to admin_solidus_tiny_accounts_path end @tiny_account = ::SolidusTiny::Account.new @payment_methods = ::Spree::PaymentMethod.all.pluck(:name, :id) @shipping_methods = ::Spree::ShippingMethod.all.pluck(:name, :id) @tiny_account.payment_methods.build @tiny_account.shipping_methods.build @tiny_account.sellers.build end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 11 def show redirect_to edit_admin_solidus_tiny_account_path(@tiny_account.id) end |
#update ⇒ Object
45 46 47 48 49 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 45 def update @tiny_account.sellers.find_by(seller_params[:default_seller]).update(default: true) @tiny_account.update account_params redirect_to edit_admin_solidus_tiny_account_path(@tiny_account.id) end |
#upsert_sellers ⇒ Object
56 57 58 59 60 |
# File 'app/controllers/spree/admin/solidus_tiny/accounts_controller.rb', line 56 def upsert_sellers ::SolidusTiny::UpsertSellersJob.perform_later flash[:success] = "Vendedores atualizados" redirect_to admin_solidus_tiny_accounts_path end |