Foreman Host create API always giving me AbstractController::DoubleRenderError while creating new host from UI

When i am calling foreman host create API - /api/hosts.json
it always giving me below error

my code is :

headers = {"content-type" => "application/json", "accept" => "application/json"}
#lookupkey = LookupKey.find_by_id(148)
uri = URI.parse("https://192.168.21.3/api/hosts.json")
host_params = params[:host]
Rails.logger.error "4444444444444444444444444444444444444444444444#{host_params}"
hostgroup = Hostgroup.find_by_id(host_params[:hostgroup_id])
Rails.logger.error "55555555555555555555555555555555555555555555555#{hostgroup}"
   # compute_profile_attributes = hostgroup.try(:compute_profile).try(:compute_attributes).try(:last)  
   # Rails.logger.error "666666666666666666666666666666666666666666666666666#{compute_profile_attributes}"     
host_param = {
              managed: true, 
              build: true, 
              compute_resource_id: host_params[:compute_resource_id],
              ip: host_params[:ip],
              provision_method: "build",
              architecture_id: hostgroup.architecture_id,
              domain_id: hostgroup.domain_id,
              subnet_id: hostgroup.subnet_id,
              environment_id: hostgroup.environment_id,
              hostgroup_id: hostgroup.id, 
              mac: host_params[:mac], 
              medium_id: hostgroup.medium_id, 
              name: host_params[:name], 
              root_pass: host_params[:password], 
              operatingsystem_id: hostgroup.operatingsystem_id,
              ptable_id: hostgroup.ptable_id
              } 
              
http = Net::HTTP.new(uri.host, uri.port)
Rails.logger.error "xdddddddddddddddddddddddd#{http}"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri, headers)
Rails.logger.error "xdddddddddddddddddddddddd#{request.inspect}"
request.body = host_param.to_json
request.basic_auth 'abcd', 'abcd'        
Rails.logger.error "xdddddddddddddddddddddddd#{request.inspect}"
response = http.request(request)
Rails.logger.error "xdddddddddddddddddddddddd#{response.inspect}"
#if response.code == "301"
#  response =  Net::HTTP.get_response(URI.parse(response.header['location']))
   #      Rails.logger.error "222222222222222222222222222222222222222222222222222222#{response.inpsect}"
   # end
   @body = response.body 

production.log:

Started POST "/api/hosts.json" for 192.168.21.3 at 2018-08-07 14:16:15 +0530
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Processing by Api::V2::HostsController#create as JSON
2018-08-07 14:16:15 f6b8c3f4 [app] [I]   Parameters: {"managed"=>true, "build"=>true, "compute_resource_id"=>"", "ip"=>"192.168.21.115", "provision_method"=>"build", "architecture_id"=>3, "domain_id"=>1, "subnet_id"=>1, "environment_id"=>1, "hostgroup_id"=>3, "mac"=>"ec:b1:d7:50:40:e9", "medium_id"=>nil, "name"=>"ervin-hauffe", "root_pass"=>"[FILTERED]", "operatingsystem_id"=>7, "ptable_id"=>nil, "apiv"=>"v2", :host=>{"build"=>true, "provision_method"=>"build", "compute_resource_id"=>"", "ip"=>"192.168.21.115", "mac"=>"ec:b1:d7:50:40:e9", "managed"=>true, "name"=>"ervin-hauffe", "root_pass"=>"[FILTERED]", "architecture_id"=>3, "domain_id"=>1, "environment_id"=>1, "hostgroup_id"=>3, "medium_id"=>nil, "operatingsystem_id"=>7, "ptable_id"=>nil, "subnet_id"=>1}}
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Current user: foreman_admin (administrator)
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Current user: foreman_admin (administrator)
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Current user: admin (administrator)
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Authorized user admin(Admin User)
2018-08-07 14:16:15 f6b8c3f4 [app] [I] Current user: admin (administrator)
2018-08-07 14:16:15 f6b8c3f4 [app] [W] Action failed
 | AbstractController::DoubleRenderError: Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
 | /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:15:in `render'

Hi, this looks like a bug to me, the controller tries to render multiple times. What Foreman version are you on?

I am on foreman Version 1.15.6

Is there any work around of this.

I would recommend to upgrade, 1.15.6 is out of support and it might have been fixed in the newer versions.