我正在尝试按照下面的属性集对我的产品属性进行分组,即我将Size作为属性集并希望在其下分组Small,Medium,Large等。
这是我目前的代码,但我收到了一些错误
- Property.all.group_by(&:property_set_id).each do |property_set, properties|
h3= property_set.name
- properties.each do |property|
= property.property_set.name
.property_form.left.span-9.last
- checked = property_set.name && property_set.properties.include?(property)
label.mdl-switch.mdl-js-switch.mdl-js-ripple-effect for=property.name
= check_box_tag "prototype[property_ids][]", property.id, checked, :class => 'mdl-switch__input', :id => property.name
span.mdl-switch__label= property.name
def edit
@properties = Property.all
@property_set = PropertySet.includes(:properties).find(params[:id])
end
答案 0 :(得分:1)
分组property_set
之后的这一行将是id
- Property.all.group_by(&:property_set_id).each do |property_set, properties|
类似的东西:
{ 1 => [<#Property>], 2 => [<#Property>] }
因此,您无法在整数值上调用.name
。你需要从db
h3= PropertySet.find(property_set).try(:name)
# or
h3= properties.find{ |p| p.property_set_id == property_set}.property_set.try(:name) # to avoid query