From 0a6b2fe19add798f52a93d269631361edfaabb22 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 28 Dec 2016 15:08:09 +0200 Subject: [PATCH] Move account creation from registrar model to admin/registrars controller --- app/controllers/admin/registrars_controller.rb | 9 +++++++-- app/models/registrar.rb | 5 ----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index be4b7d092..611687f9b 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -17,10 +17,15 @@ class Admin::RegistrarsController < AdminController def create @registrar = Registrar.new(registrar_params) - if @registrar.save + begin + @registrar.transaction do + @registrar.save! + @registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR') + end + flash[:notice] = I18n.t('registrar_added') redirect_to [:admin, @registrar] - else + rescue ActiveRecord::RecordInvalid flash.now[:alert] = I18n.t('failed_to_add_registrar') render 'new' end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 003956f88..162aef292 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -57,11 +57,6 @@ class Registrar < ActiveRecord::Base RegenerateRegistrarWhoisesJob.enqueue id end - after_create :create_cash_account - def create_cash_account - accounts.create(account_type: Account::CASH, currency: 'EUR') - end - class << self def search_by_query(query) res = search(name_or_reg_no_cont: query).result