0

我正在使用 rails 3.2.11 并尝试将对象从视图传递到自定义助手中,但我不明白为什么会这样:

- @data = { name: "Add Skus", f: f, container: "skus", association: :skus, child_association: :images, options: @sku_options }
= link_to_add_fields @data

但这不是:

= link_to_add_fields { name: "Add Skus", f: f, container: "skus", association: :skus, child_association: :images, options: @sku_options }

我得到错误:syntax error, unexpected ':', expecting '}'

辅助方法:

def link_to_add_fields(data)
  STDOUT << "name: " + data[:name].to_s + " :: "
  STDOUT << "f.object: " + data[:f].object.to_s + " :: "
  STDOUT << "association: " + data[:association].to_s + " :: "
  STDOUT << "container: " + data[:container].to_s + " :: "

  if data[:child_association]
    STDOUT << "child_association: " + data[:child_association].to_s + " :: "
  end
end
4

1 回答 1

0

在您的第二个示例中,由于大括号,Ruby 认为您将块作为参数传递。在您的选项周围添加括号,或去掉大括号:

= link_to_add_fields({name: "Add Skus", f: f, container: "skus", association: :skus, child_association: :images, options: @sku_options})

或者

= link_to_add_fields name: "Add Skus", f: f, container: "skus", association: :skus, child_association: :images, options: @sku_options
于 2013-06-14T00:32:23.197 回答