Reputation: 683
I am trying to parse db-record data in to my haml-template file for filtering purposes.(isotope jquery)
House model
def features_to_html_class
"#{(guests + bedrooms + type + amenities).map(&:name).join(' ')}"
end
House index haml view
- @houses.each do |house|
.item{:class => house.features_to_html_class }
I get the error message undefined method `map'. The values from the db are integers (guests/bedrooms) and strings (type / amenities)
What am I doing wrong?
Upvotes: 0
Views: 1173
Reputation: 12503
Are you getting that in the features_to_html_class
? You might want to check for nil
arrays. You can do that with compact
easily.
def features_to_html_class
(guests + bedrooms + type + amenities).compact.map(&:name).join(' ')
end
Upvotes: 1