Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 奇怪的未定义方法';全部';和集合\u选择错误_Ruby On Rails 3_Nested Attributes - Fatal编程技术网

Ruby on rails 3 奇怪的未定义方法';全部';和集合\u选择错误

Ruby on rails 3 奇怪的未定义方法';全部';和集合\u选择错误,ruby-on-rails-3,nested-attributes,Ruby On Rails 3,Nested Attributes,我有一个这样的表格(简化了,但你明白了): 在集合中选择行 模板。所有都通过控制器和控制台工作。如果我写了一个@templates=Template.all并在集合中使用@templates选择行,那么我会得到以下错误: undefined method `merge' for :name:Symbol 有什么想法吗?解决了。这是令人烦恼的简单 <%= price.collection_select(:template_id, @templates, :id, :name) %>

我有一个这样的表格(简化了,但你明白了):

集合中选择

模板。所有
都通过控制器和控制台工作。如果我写了一个
@templates=Template.all
并在
集合中使用
@templates
选择
行,那么我会得到以下错误:

undefined method `merge' for :name:Symbol

有什么想法吗?

解决了。这是令人烦恼的简单

<%= price.collection_select(:template_id, @templates, :id, :name) %>


重复。嗯。

解决了它。这是令人烦恼的简单

<%= price.collection_select(:template_id, @templates, :id, :name) %>


重复。嗯。

你可以在前面加两个冒号。e、 g,

<%= price.collection_select(:price, :template_id, ::Template.all, :id, :name) %>


但是我认为,您应该避免使用模板作为模型名,因为它是rails

您可以通过在前面加两个冒号来实现。e、 g,

<%= price.collection_select(:price, :template_id, ::Template.all, :id, :name) %>


但我认为,您应该避免使用模板作为模型名称,因为它是rails

一个选项是将模板作为实例变量公开(或作为发送到视图层的任何内容的一部分),并完全避免解决问题。一个选项是将模板作为实例变量公开(或作为发送到视图层的任何内容的一部分)并完全避免解决问题。