我试图在正确提交表单时呈现错误。所以我的形式打它失败在rails中呈现错误消息
指数从控制器,def index
@player_types = squad.player_types
end
索引视图
然后,
<%= form_tag({:action => :update}, :method => :put) do %>
<%= render 'shared/error_messages' %>
<table>
<% @player_types.order(:number).each do |p_type| %>
...do something...
<%end%>
<%end%>
在错误消息我有一个简单的错误检查(现在)
<% if @player_types.errors.any? %>
因为undefined method 'errors'
在大多数的,网上是有例子,错误方法在使用new
实例化对象时给出。但在我的情况下,对象最初有内容要显示。我在这里做错了什么,我是否应该使用@player_types
来捕捉错误?
编辑:正如评论所说,我在错误消息循环
<% @player_types.each do |p_type| %>
<% if @p_type.errors.any? %>
<%end%>
<%end%>
什么是完整的错误信息? – 2014-11-20 22:45:50
我对此很陌生,尚未初始化它。我的动机是让索引页正常工作,然后担心这些消息。这是我应该做的事吗? – Trancey 2014-11-20 22:48:25
你不想更新很多播放器对象吗?那么使用一种形式来做到这一点可能是错误的做法。你最终的目标是什么? – rorofromfrance 2014-11-20 22:51:28