48 lines
1.4 KiB
Ruby
48 lines
1.4 KiB
Ruby
class InstanceController < ApplicationController
|
|
def create
|
|
zone = create_instance_params
|
|
public_id = Nanoid.generate(size: 6)
|
|
name = Spicy::Proton.pair(" ")
|
|
password = Nanoid.generate(size: 3, alphabet: "0123456789")
|
|
instance = Instance.new(zone: zone, public_id: public_id, name: name, password: password)
|
|
if instance.save
|
|
redirect_to(show_instance_path(public_id: public_id))
|
|
end
|
|
end
|
|
|
|
def show
|
|
@instance = Instance.includes(:pops).find_by(public_id: show_instance_params)
|
|
end
|
|
|
|
def pop
|
|
instance_id, nm = pop_instance_params
|
|
parent_instance = Instance.find_by(public_id: instance_id)
|
|
pop = Pop.new(instance_id: parent_instance.id, name: nm)
|
|
if pop.save
|
|
@instance = Instance.includes(:pops).find_by(public_id: instance_id)
|
|
render partial: "list", locals: { instance: @instance }
|
|
end
|
|
end
|
|
|
|
def reset
|
|
instance_id, nm = pop_instance_params
|
|
parent_instance = Instance.find_by(public_id: instance_id)
|
|
Pop.delete_by(instance_id: parent_instance.id, name: nm)
|
|
@instance = Instance.includes(:pops).find_by(public_id: instance_id)
|
|
render partial: "list", locals: { instance: @instance }
|
|
end
|
|
|
|
private
|
|
|
|
def create_instance_params
|
|
params.expect(:zone)
|
|
end
|
|
|
|
def show_instance_params
|
|
params.expect(:public_id)
|
|
end
|
|
|
|
def pop_instance_params
|
|
params.expect(:instance, :nm)
|
|
end
|
|
end
|