The STI for Hosts (Host::Managed) breaks the accepts_nested_attributes_for
This error in the current 3.0.20 "develop" branch and the new 3.2.13 branch.
When a hostgroup for host is changed, the Parameters tab show "Loading parameters…" and doesn't load
The error is
HostParameter Load (0.7ms) SELECT "parameters".* FROM "parameters" WHERE "parameters"."type" IN ('HostParameter') AND "parameters"."reference_id" IS NULL AND "parameters"."id" IN (7)
ActiveRecord::RecordNotFound: Couldn't find HostParameter with ID=7 for Host::Managed with ID=
The error is caused by Host.new on hosts_controller.rb#460
I can duplicate this error in the console by
1.9.3p385 :054 > params = {"name"=>"fdev", "hostgroup_id"=>"23", "environment_id"=>"1", "puppetclass_ids"=>[""], "managed"=>"t", "progress_report_id"=>"52e4128d-560d-47f1-989f-9a9d9698ee60", "mac"=>"52:54:00:05:49:de", "domain_id"=>"6", "ip"=>"10.35.27.3", "updated_at"=>"1364484907", "interfaces_attributes"=>{"new_interfaces"=>{"_destroy"=>"false", "type"=>"Nic::Managed", "mac"=>"", "name"=>"", "domain_id"=>"", "ip"=>"staff@kehila.org", "provider"=>"IPMI"}}, "architecture_id"=>"", "provision_method"=>"build", "disk"=>"", "root_pass"=>"123456", "host_parameters_attributes"=>{"0"=>{"name"=>"RESERVED", "value"=>"false", "_destroy"=>"false", "nested"=>"", "id"=>"7"}}, "is_owned_by"=>"", "enabled"=>"1", "model_id"=>"2", "comment"=>"", "overwrite"=>"false"}
1.9.3p385 :055 > Host.new(params)
HostParameter Load (0.7ms) SELECT "parameters".* FROM "parameters" WHERE "parameters"."type" IN ('HostParameter') AND "parameters"."reference_id" IS NULL AND "parameters"."id" IN (7)
ActiveRecord::RecordNotFound: Couldn't find HostParameter with ID=7 for Host::Managed with ID=
It seems to be an STI issue with the param host_parameters_attributes
In managed.rb
has_many :host_parameters, :dependent => :destroy, :foreign_key => :reference_id
accepts_nested_attributes_for :host_parameters, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true
Btw, for the example data, there is a host_parameter with id = 7
1.9.3p385 :058 > Host.find(394).host_parameters
Host::Managed Load (0.8ms) SELECT "hosts".* FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = $1 LIMIT 1 [["id", 394]]
HostParameter Load (0.5ms) SELECT "parameters".* FROM "parameters" WHERE "parameters"."type" IN ('HostParameter') AND "parameters"."reference_id" = 394