collection_select中的Ruby on Rails集合输出

时间:2016-07-27 08:17:53

标签: ruby-on-rails ruby ruby-on-rails-4

我有这段代码:

    <%= collection_select :channel, @channelList, :id, :channelname, {prompt: (t "channel.add.prompt")}, class: "form-control"%>

得到了这个错误:

enter image description here

它是正常的活跃关系

enter image description here

在这种情况下,我的错误是什么?

感谢

1 个答案:

答案 0 :(得分:1)

http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select

您必须指定:object, method, collection, value_method, text_method,您可能忘记设置object参数。

这将使这个:

<%= collection_select :object, :channel, @channelList, :id, :channelname, {prompt: (t "channel.add.prompt")}, class: "form-control"%>

(将:object替换为您要将频道保存到的对象