【问题标题】:undefined method `stringify_keys' for false:FalseClass未定义的方法 `stringify_keys' for false:FalseClass
【发布时间】:2014-06-26 15:31:18
【问题描述】:

这段代码给了我这个错误

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

有什么问题?

【问题讨论】:

    标签: ruby-on-rails ruby helper


    【解决方案1】:

    改变这个:

    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 的更多信息。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-05
        • 1970-01-01
        • 2016-08-16
        • 2012-08-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多