2013-01-17 26 views
0

我有这样的形式(简化,但你的想法):哪个渲染时怪异的未定义的方法“全部”和collection_select错误

<%= form_for(@brand, :html => { :class => "form-horizontal" }) do |f| %> 
    <%= f.fields_for :prices do |price| %> 
    <%= price.collection_select(:price, :template_id, Template.all, :id, :name) %> 
    <% end %> 
    <%= f.submit "Save", :class => 'btn btn-primary' %> 
<% end %> 

给了我这个错误

undefined method `all' for ActionView::Template:Class 

collection_select行。

Template.all从控制器和控制台工作。如果我写的collection_select线@templates = Template.all和使用@templates然后我得到这个错误:

undefined method `merge' for :name:Symbol 

有什么想法?

+0

一种选择是揭露模板作为一个实例变量(或为任何你一部分发送到视图层)并完全避免解决问题。 –

回答

1

解决了它。这是令人讨厌的简单。

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

复制。 Eugh。

2

你可以用两个冒号加前缀。例如,

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

但我相信,你应该避免使用模板型号名称,因为它是轨道Action View Template