Ruby on rails 使用ruby on rails通过表单编辑Shopify元字段数据时没有方法错误

Ruby on rails 使用ruby on rails通过表单编辑Shopify元字段数据时没有方法错误,ruby-on-rails,ruby-on-rails-3.2,shopify,nomethoderror,Ruby On Rails,Ruby On Rails 3.2,Shopify,Nomethoderror,作为我为Shopify网站定制的一部分,我正在尝试编写一个只允许编辑特定元字段的工具 在索引页面上,我将列出与我希望用户能够通过表单编辑的特定元字段相关联的各种集合、产品、页面和博客文章 。。。就我的一生而言,我就是看不出我错过了什么!!非常感谢为解决此问题提供的任何帮助:) 所以。。。我们走!当用户单击“编辑”(这会将他们带到一个表单,编辑该集合、产品、页面或博客文章的特定元字段)时,我在浏览器中遇到以下错误: NoMethodError in Metafields#edit Showing

作为我为Shopify网站定制的一部分,我正在尝试编写一个只允许编辑特定元字段的工具

在索引页面上,我将列出与我希望用户能够通过表单编辑的特定元字段相关联的各种集合、产品、页面和博客文章

。。。就我的一生而言,我就是看不出我错过了什么!!非常感谢为解决此问题提供的任何帮助:)

所以。。。我们走!当用户单击“编辑”(这会将他们带到一个表单,编辑该集合、产品、页面或博客文章的特定元字段)时,我在浏览器中遇到以下错误:

NoMethodError in Metafields#edit

Showing /Users/james/code/test-app/app/views/metafields/_form.html.erb where line #1 raised:

undefined method `shopify_api_metafield_path' for #<#<Class:0x007facf51992a0>:0x007facf520fec8>

Extracted source (around line #1):
1: <%= form_for(@metafield) do |f| %>
文件“/views/metafields/index.html.erb”如下所示:

class Metafield < ActiveRecord::Base
  attr_accessible :namespace, :key, :value, :value_type, :description, :id
end
<h1>Listing metafields</h1>

<table>
  <tr>
    <th>Namespace</th>
    <th>Key</th>
    <th>Value</th>
    <th>Value type</th>
    <th>Description</th>
    <th>Id</th>
    <th></th>
  </tr>

<% @metafields.each do |metafield| %>
  <tr>
    <td><%= metafield.namespace %></td>
    <td><%= metafield.key %></td>
    <td><%= metafield.value %></td>
    <td><%= metafield.value_type %></td>
    <td><%= metafield.description %></td>
    <td><%= metafield.id %></td>
    <td><%= link_to 'Edit', edit_metafield_path(metafield) %></td>
  </tr>
<% end %>
</table>
<h1>Editing metafield</h1>

<%= render 'form' %>

<%= link_to 'Back', metafields_path %>
列出元字段
名称空间
钥匙
价值
值类型
描述
身份证件
文件“/views/metafields/edit.html.erb”如下所示:

class Metafield < ActiveRecord::Base
  attr_accessible :namespace, :key, :value, :value_type, :description, :id
end
<h1>Listing metafields</h1>

<table>
  <tr>
    <th>Namespace</th>
    <th>Key</th>
    <th>Value</th>
    <th>Value type</th>
    <th>Description</th>
    <th>Id</th>
    <th></th>
  </tr>

<% @metafields.each do |metafield| %>
  <tr>
    <td><%= metafield.namespace %></td>
    <td><%= metafield.key %></td>
    <td><%= metafield.value %></td>
    <td><%= metafield.value_type %></td>
    <td><%= metafield.description %></td>
    <td><%= metafield.id %></td>
    <td><%= link_to 'Edit', edit_metafield_path(metafield) %></td>
  </tr>
<% end %>
</table>
<h1>Editing metafield</h1>

<%= render 'form' %>

<%= link_to 'Back', metafields_path %>
编辑元字段
文件“/views/metafields/_form.html.erb”如下所示(显然,第1行抛出了错误…):


禁止保存此元字段:






提前谢谢

像在_form.html.erb中那样在视图片段中嵌套表单不是一个好主意

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

      <ul>
      <% @metafield.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
因为
form\u for()
帮助程序试图找出将在表单提交时呈现的视图的路径。此路径由
shopify\u api\u metafield\u path()
helper返回,它是错误消息中未定义的方法


关于
error\u messages\u for()
helper,它不会转换为HTML表单标记,可以在局部视图中使用,而无需嵌套HTML表单。请参阅更多

谢谢niebelung。我是一个ruby新手,所以不熟悉“错误消息”。你能说得更具体一点,或者发送更多的信息吗。关于如何使用“error\u messages\u for”帮助程序而不是表单\u for()帮助程序?我认为使用form_for()是“正确的”ruby实践,因为这都是使用标准ruby scaffold命令生成的。如果愿意,您当然可以使用form_for(),但您必须记住,在另一个表单中呈现一个表单是无效的(您已经在
edit.html.erb
视图中呈现了一个表单)。如果您仍然想使用form_for()helper,请尝试将其放在您的
标记上方的编辑视图中。我一直在反复考虑您上周提出的建议,包括完全重建应用程序(以防是其他事情影响了这一点)。。。而且。。。无效:/当我尝试用建议更新model metafield.rb时,我得到以下结果:“metafields控制器中的TypeError#编辑类metafield的超类不匹配”
class ShopifyAPI::Metafield < ActiveRecord::Base
{
}