-
Notifications
You must be signed in to change notification settings - Fork 152
How to add Dropletkit in Rails
Nopal Consulting edited this page Jul 24, 2019
·
1 revision
First Install the gem
gem 'droplet_kit'
then create initializer
config/initializers/digitalocean.rb
then call the constant into your controller or model
def create
@hosting = Hosting.new(hosting_params)
client = DropletKit::Client.new(access_token: ENV['digitalocean_token'])
droplet = DropletKit::Droplet.new(
name: 'mysite.com',
region: 'nyc3',
image: 'ubuntu-14-04-x64',
size: 's-1vcpu-1gb'
)
created = client.droplets.create(droplet)
respond_to do |format|
if @hosting.save
format.html { redirect_to @hosting, notice: 'Hosting was successfully created.' }
format.json { render :show, status: :created, location: @hosting }
else
format.html { render :new }
format.json { render json: @hosting.errors, status: :unprocessable_entity }
end
end
end
or if you want use after_create
call inside your model.