未定义的方法`map'

时间:2012-11-11 15:50:39

标签: ruby-on-rails ruby-on-rails-3 haml

我正在尝试将db-record数据解析到我的haml-template文件中以进行过滤。(isotope jquery)

众议院模特

def features_to_html_class
  "#{(guests + bedrooms + type + amenities).map(&:name).join(' ')}"
end

众议院索引haml视图

- @houses.each do |house|
  .item{:class => house.features_to_html_class }

我收到错误消息undefined method`map'。 db中的值是整数(来宾/卧室)和字符串(类型/设施)

我做错了什么?

1 个答案:

答案 0 :(得分:1)

你是否在features_to_html_class中得到了这个?您可能想要检查nil数组。您可以轻松地使用compact执行此操作。

def features_to_html_class
  (guests + bedrooms + type + amenities).compact.map(&:name).join(' ')
end