internetee-registry/app/controllers/admin/registrars_controller.rb
Artur Beljajev 837f326ef6 Merge branch 'master' into registry-623
# Conflicts:
#	app/controllers/admin/registrars_controller.rb
#	app/models/registrar.rb
#	app/views/admin/registrars/_billing.html.erb
#	app/views/admin/registrars/show.html.erb
#	config/locales/admin/registrars.en.yml
#	config/locales/en.yml
#	db/migrate/20180309053424_add_registrars_unique_constraints.rb
#	db/structure.sql
#	test/fixtures/registrars.yml
#	test/integration/admin/registrars/delete_test.rb
#	test/integration/admin/registrars/new_test.rb
#	test/models/registrar_test.rb
2018-03-29 12:13:59 +03:00

81 lines
2.2 KiB
Ruby

module Admin
class RegistrarsController < BaseController
load_and_authorize_resource
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
def search
render json: Registrar.search_by_query(params[:q])
end
def index
@q = Registrar.joins(:accounts).ordered.search(params[:q])
@registrars = @q.result.page(params[:page])
end
def new
@registrar = Registrar.new
end
def create
@registrar = Registrar.new(registrar_params)
if @registrar.valid?
@registrar.transaction do
@registrar.save!
@registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR')
end
redirect_to [:admin, @registrar], notice: t('.created')
else
render :new
end
end
def edit;
end
def update
if @registrar.update(registrar_params)
redirect_to [:admin, @registrar], notice: t('.updated')
else
render :edit
end
end
def destroy
if @registrar.destroy
flash[:notice] = t('.deleted')
redirect_to admin_registrars_url
else
flash[:alert] = @registrar.errors.full_messages.first
redirect_to admin_registrar_url(@registrar)
end
end
private
def set_registrar
@registrar = Registrar.find(params[:id])
end
def registrar_params
params.require(:registrar).permit(:name,
:reg_no,
:street,
:city,
:state,
:zip,
:country_code,
:email,
:phone,
:website,
:code,
:test_registrar,
:vat_no,
:vat_rate,
:accounting_customer_code,
:billing_email,
:language)
end
end
end