Project

General

Profile

« Previous | Next » 

Revision ae96cb70

Added by Stephen Benjamin almost 6 years ago

fixes #24046 - return id as str for name as last resort

Foreman HasManyCommon concern uses 'id' as a value of last resort for
the name of an attribute. But Rails expects this value to a return a
string. This causes a problem for Katello. Take a look at the output
here in Katello:

```
irb(main):001:0> Host.first
Hirb Error: undefined method `gsub' for 2:Integer
```

Where's that coming from?

```

irb(main):006:0> Host.first.content_facet_attributes.to_s
=> 2
irb(main):007:0> Host.first.content_facet_attributes.to_s.is_a?(String)
=> false

```

View differences:

app/models/concerns/has_many_common.rb
# calls method :name or whatever is defined in attr_name :title
def name_method
send(self.class.attribute_name)
send(self.class.attribute_name).to_s
end
module ClassMethods
# default attribute used by *_names and *_name is :name
# if :name doesn't exist, :id is used, so it doesn't error out if attr_name :field is not defined
# most likely model will have attr_name :field to overwrite attribute_name
# if :name doesn't exist, :id as a string is used, so it doesn't error out
# if attr_name :field is not defined most likely model will have attr_name
# :field to overwrite attribute_name
def attribute_name
if has_name?
:name

Also available in: Unified diff