Move account creation from registrar model to admin/registrars controller

This commit is contained in:
Artur Beljajev 2016-12-28 15:08:09 +02:00
parent c1cb598da1
commit 0a6b2fe19a
2 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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