Ruby-On-Rails-don';t删除和更新元素

Ruby-On-Rails-don';t删除和更新元素,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,我创建了一个网站:当我想添加新类别或更新它时,我得到一个错误 日志上写着: FATAL -- : ActionView::Template::Error (undefined method `error_messages' for #<ActionView::Helpers::FormBuilder:0x000000031b5fa0>): 1: <%= f.error_messages %> 2: <p> 3: <%

我创建了一个网站:当我想添加新类别或更新它时,我得到一个错误

日志上写着:

FATAL -- : 
ActionView::Template::Error (undefined method `error_messages' for #<ActionView::Helpers::FormBuilder:0x000000031b5fa0>):
    1: <%= f.error_messages %> 
    2: <p> 
    3:     <%= f.label :name %><br /> 
    4:   <%= f.text_field :name %> 
  app/views/categories/_form.html.erb:1:in `_app_views_categories__form_html_erb___3155759666617831256_25435480'
  app/views/categories/edit.html.erb:3:in `block in _app_views_categories_edit_html_erb__3036452290204433295_27619860'
  app/views/categories/edit.html.erb:2:in `_app_views_categories_edit_html_erb__3036452290204433295_27619860'
致命--:

ActionView::Template::Error(不推荐使用
FormBuilder
类的
Error\u messages
方法“Error\u messages”的未定义方法“Error\u messages”。您可以将自定义表单生成器与类似的方法一起使用(使用类似的方法:),也可以创建一个实现相同功能的帮助器


无论采用哪种方式,您都必须从模型中读取错误(使用
model.errors
)并返回一个字符串,其中的值格式如您所需。

错误存在于@category模型上,而不是表单生成器上。我将执行以下操作:

<h1>Zmiana kategorii</h1>
<%= form_for(@category) do |f| %>
  <% if @category.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>

      <ul>
      <% @category.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <%= render :partial => 'form', :locals => { :f => f } %>
  <p>
    <%= f.submit "Modyfikuj" %>
  </p>
<% end %>
<%= link_to 'Pokaz', @category %> |
<%= link_to 'Wyswietl', categories_path %>
Zmiana kategorii
禁止保存此类别:
'form',:locals=>{:f=>f}%>

|

代码是Rails scaffold默认的功能…

你可能有一些简单的教程如何创建帮助程序或读取错误??是的。看看这个。我没有测试它,但我认为它可以工作。但是我的文件类别\u helper.rb是:
模块分类帮助端
我可以粘贴你所有的代码来替换它吗?我所有的项目文件我在上面更新了我的答案,你需要一直解决同一个问题。所有kode文件都是hiere,没有你的kode beacue它不工作。你能看看这个吗?打开拉请求向你展示它工作…非常感谢。它现在工作了。还有一个问题:你能告诉我为什么删除不工作吗??
<h1>Zmiana kategorii</h1>
<% form_for(@category) do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
  <p>
    <%= f.submit "Modyfikuj" %>
  </p>
<% end %>
<%= link_to 'Pokaz', @category %> |
<%= link_to 'Wyswietl', categories_path %>
<%= f.error_messages %> 
<p> 
    <%= f.label :name %><br /> 
  <%= f.text_field :name %> 
</p> 
<p> 
    <%= f.label :parent_id %><br /> 
  <%= f.collection_select :parent_id, @all_categories, :id, :long_name %> 
</p>
<h1>Zmiana kategorii</h1>
<%= form_for(@category) do |f| %>
  <% if @category.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>

      <ul>
      <% @category.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <%= render :partial => 'form', :locals => { :f => f } %>
  <p>
    <%= f.submit "Modyfikuj" %>
  </p>
<% end %>
<%= link_to 'Pokaz', @category %> |
<%= link_to 'Wyswietl', categories_path %>