undefined方法`stringify_keys' for false:FalseClass

时间:2014-06-26 15:31:19

标签: ruby-on-rails ruby helper

给我这个代码的错误

module Spree::Admin::ProductsHelper
  def stores_checkbox
    capture do
      Spree::Store.all.each do |store| 
        concat hidden_field_tag "product[store_ids][]", store.id, @product.stores.include?(store)
      end
    end 
  end
end

但这个没问题......

module Spree::Admin::ProductsHelper
  def stores_checkbox
    capture do
      Spree::Store.all.each do |store| 
        concat check_box_tag "product[store_ids][]", store.id, @product.stores.include?(store), :style => "display: none;"
      end
    end 
  end
end

有什么问题?

2 个答案:

答案 0 :(得分:2)

改变这个:

hidden_field_tag "product[store_ids][]", store.id, @product.stores.include?(store)

为:

hidden_field_tag "product[store_ids][]", store.id

问题:hidden_field_tag期待一个哈希,因为它是最后一个参数,但你传递的是false(布尔值)。

我建议的更改会将产品store_id添加为表单上的隐藏字段,其值设置为store.id

您可以阅读有关hidden_​​field_tag here的更多信息。

答案 1 :(得分:0)

您的第三个参数需要是一个选项哈希。 check_box_tag具有不同的方法签名,其中第三个参数是初始检查状态,而选项哈希是第四个参数。每当您看到stringify_keys错误时,您的第一个猜测应该是预期哈希,并且您提供了其他内容。只是摆脱你的第三个参数,它应该工作正常。

相关问题