Managing multiple domains in a rails application error: "NameError (uninitialized constant #<Class:0x0000563d7bf62250>::Heroku):" Managing multiple domains in a rails application error: "NameError (uninitialized constant #<Class:0x0000563d7bf62250>::Heroku):" heroku heroku

Managing multiple domains in a rails application error: "NameError (uninitialized constant #<Class:0x0000563d7bf62250>::Heroku):"


To get around error in question you can try writing classname as ::Heroku, that will make ruby to look for it in correct scope.

But Heroku legacy api has been disabled, so you should use their new platform-api:

heroku = PlatformAPI.connect(ENV['HEROKU_API_KEY']) # note that you may also have to use a new keydomains = heroku.domain.list(ENV['APP_NAME'])...heroku.domain.create(ENV['APP_NAME'], ...)

also to check for domain presence you can use domain.info api method instead of fetching all domains that are not needed.

Keep in mind that callbacks are not the best place to make any external calls: if the api call fails for some reason (temporary network problems, api outage, server restart, etc) - whole transaction will be rolled back, item will not be saved and you can loose data. Better way is to enqueue a background job there, which will handle domains later, can retry if needed and so on.