简单形式 collection_radio_buttons 显示记录模型中的项目
Simple form collection_radio_buttons show items from record model
我想在单选按钮中显示所有可用类型以便单击和select其中的一个
= f.collection_radio_buttons :type_id, Type.all, :label => "Available Types"
但我收到以下错误
wrong number of arguments (given 3, expected 4..6)
如何修正 collection_radio_buttons
以获得正确数量的参数?
这是 api 关于 collection_radio_buttons 的文档:
http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormBuilder/collection_radio_buttons
这绝对表明您至少需要 4 个参数(最少):
method, collection, value_method, text_method, options = {}
您提供了 3 - 一个方法 :type_id
一个集合 Type.all
您还提供了选项,但错过了 value_method
和 text_method
这就是您需要添加的内容才能使这项工作正常进行。
对于 select 选项的 text/values,每个 Type
将调用什么方法?通常这类似于::id
(代表 value_method
)和类似 :name
(代表 text_method
)
我想在单选按钮中显示所有可用类型以便单击和select其中的一个
= f.collection_radio_buttons :type_id, Type.all, :label => "Available Types"
但我收到以下错误
wrong number of arguments (given 3, expected 4..6)
如何修正 collection_radio_buttons
以获得正确数量的参数?
这是 api 关于 collection_radio_buttons 的文档:
http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormBuilder/collection_radio_buttons
这绝对表明您至少需要 4 个参数(最少):
method, collection, value_method, text_method, options = {}
您提供了 3 - 一个方法 :type_id
一个集合 Type.all
您还提供了选项,但错过了 value_method
和 text_method
这就是您需要添加的内容才能使这项工作正常进行。
对于 select 选项的 text/values,每个 Type
将调用什么方法?通常这类似于::id
(代表 value_method
)和类似 :name
(代表 text_method
)