【问题标题】:How do I add variable to grouped_collection_select group_method?如何将变量添加到分组集合选择组方法?
【发布时间】:2015-02-12 15:40:11
【问题描述】:

作品

 grouped_collection_select(:event, :id, EventGroup.all, 'events', :name, :id, :name)

NoMethodError

 grouped_collection_select(:event, :id, EventGroup.all, 'events(item)', :name, :id, :name)

有没有办法在 group_method 中包含一个变量?

【问题讨论】:

    标签: ruby-on-rails forms actionview


    【解决方案1】:

    我认为这应该可行 grouped_collection_select(:event, :id, EventGroup.all, "events, #{item}", :name, :id, :name)

    此方法使用 EventGroup.all.send 从字符串中调用该方法。

    【讨论】:

    • 呃,对了,arg 属于 Object.send 的第一个参数,你应该将 *array 传递给 activeview,但它会比你需要的更早,所以我认为这是不可能的。只需要修改 ruby​​ 的 internal_send() 函数即可。
    • 我可能最终会建立自己的哈希并使用grouped_options_for_select
    猜你喜欢
    • 2021-09-25
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多