"未定义的方法`enumerable_enumerator_path'"错误 [英] " undefined method `enumerable_enumerator_path' " error
问题描述
我使用的基本支架结构。我需要什么,是通过改变发表
到 true以添加温和的行动,并查看
。在我的想法,在moderate.html我应该有能力改变和挽救他们的参数的能力所有未发布的条目列表。
下面是我的code部位:
#names_controller.rb
高清适度
@name = Name.find(:所有,:条件=> {:公布=>虚假})
respond_to代码做|格式|
的format.html
format.xml
结束
结束
#moderate.html.erb
<%的form_for @ name.each办| F | %>
&其中;%= f.error_messages%GT;
<%= f.text_field:其中%GT;
<%= f.text_field:什么%GT;
<%= f.check_box:刊登%>
&其中;%= f.submit%GT;
&所述; / P>
<%结束%GT;
相反,我得到这个错误:
NoMethodError的名称#温和
显示应用程序/视图/姓名/ moderate.html.erb,其中1号线提出:
未定义的方法`enumerable_enumerator_path'的#<而ActionView :: Base的:0x1042c3e90>
提取的源(左右线#1)
所以,你能帮助新受吗?
红宝石1.8.7(2009-06-12补丁级别174)
[通用-darwin10.0]的Rails 2.3.5
如果你想在一个单独的形式更新每一个名字,那么所有你需要做的是将上述的form_for $循环C $ C>:
<%@ name.each办| N | %>
<%的form_forñ办| F | %>
&其中;%= f.error_messages%GT;
<%= f.text_field:其中%GT;
<%= f.text_field:什么%GT;
<%= f.check_box:刊登%>
&其中;%= f.submit%GT;
&所述; / P>
<%结束%GT;
<%结束%GT;
但是,如果你想要做这一切在一个提交(单一的形式),那么我想你不能使用的form_for
。我会使用的form_tag
来创建自定义窗体来更新多个实例。这应该既为创建和编辑表单:
<%=的form_tag moderate_names_path DO%GT;
<%@ names.each办|名称| %>
<字段集>
<%= fields_for名称[#{name.id}],名字做| name_fields | %>
&其中p为H.;&其中;%= name_fields.label(:此)%计算值:&所述峰; br />&其中;%= name_fields.text_field:此%GT;&所述; / P>
&其中p为H.;&其中;%= name_fields.label(:表示)%计算值:&所述峰; br />&其中;%= name_fields.text_field:那%GT;&所述; / P>
&其中p为H.;&其中;%= name_fields.check_box:出版%GT; &其中;%= name_fields.label(:出版)%>&所述; / P>
<%结束%GT;
< /字段集>
< BR />
<%结束%GT;
&其中;%= submit_tag%GT;
<%结束%GT;
注意:我在第二个例子改变 @name
到 @names
I'm using basic scaffold structure. What I need, is to add 'moderate' action and view by changing published
to true
. In my idea, on moderate.html I should get the list of all unpublished entries with the ability to change and save their parameters.
Here are parts of my code:
#names_controller.rb
def moderate
@name = Name.find(:all, :conditions => {:published => false} )
respond_to do |format|
format.html
format.xml
end
end
#moderate.html.erb
<% form_for @name.each do |f| %>
<%= f.error_messages %>
<%= f.text_field :which %>
<%= f.text_field :what %>
<%= f.check_box :published %>
<%= f.submit %>
</p>
<% end %>
Instead I'm getting this error:
NoMethodError in Names#moderate
Showing app/views/names/moderate.html.erb where line #1 raised:
undefined method `enumerable_enumerator_path' for #<ActionView::Base:0x1042c3e90>
Extracted source (around line #1)
So, can you help to newbie please?
ruby 1.8.7 (2009-06-12 patchlevel 174)
[universal-darwin10.0] Rails 2.3.5
If you want to update each name in a separate form, then all you need to do is move the loop above form_for
:
<% @name.each do |n| %>
<% form_for n do |f| %>
<%= f.error_messages %>
<%= f.text_field :which %>
<%= f.text_field :what %>
<%= f.check_box :published %>
<%= f.submit %>
</p>
<% end %>
<% end %>
But if you'd like to do it all in one submit (a single form) then I guess you can't use form_for
. I'd use form_tag
to create a custom form to update multiple instances. This should work both for create and edit form:
<%= form_tag moderate_names_path do %>
<% @names.each do |name| %>
<fieldset>
<%= fields_for "name[#{name.id}]", name do |name_fields| %>
<p><%=name_fields.label(:this)%>: <br /><%= name_fields.text_field :this %></p>
<p><%=name_fields.label(:that)%>: <br /><%= name_fields.text_field :that %></p>
<p><%= name_fields.check_box :published %> <%=name_fields.label(:published)%></p>
<% end %>
</fieldset>
<br />
<% end %>
<%= submit_tag %>
<% end %>
NOTICE: I changed @name
to @names
in the second example
这篇关于&QUOT;未定义的方法`enumerable_enumerator_path'&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!