使用茧形宝石时无法看到部分

时间:2019-04-13 15:20:45

标签: ruby-on-rails forms nested field apache-cocoon

我已经安装了茧并根据此处概述的示例添加了所有必要的更改:https://github.com/nathanvda/cocoon/wiki/ERB-examples

但是由于某种原因,我无法在我的局部中看到任何东西。

views / order_items / _order_item_fields.html.erb:

<div class="nested-fields">
  <div class="field">
    <%= f.label :material %>
    TEST
  </div>
  <%= link_to_remove_association "remove order_item", f %>
</div>

views / orders / new.html.erb:

<div class="container text-center mt-4">
  <%= form_for @order do |f| %>
    <div class="container">
      <div class="row">
        <h2>New Order</h2>
      </div>
    </div>
    <div id="order_items">
      <%= f.fields_for :order_items do |order_item| %>
        <%= render "order_items/order_item_fields", f: order_item %>
      <% end %>
      <div class="links">
        <%= link_to_add_association "add order_item", f, :order_items %>
      </div>
    </div>
    <div class="actions">
      <%= f.submit %>
    </div>
  <% end %>
</div>

Order.rb:

class Order < ApplicationRecord
  belongs_to :user, optional: true
  has_many :order_items
  accepts_nested_attributes_for :order_items, reject_if: :all_blank, allow_destroy: true

end

我也遇到了模板丢失错误: Missing partial orders/_order_item_fields, application/_order_item_fields with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}.

我相信,如果我尝试从另一个视图文件夹渲染部分,则在部分名称之前添加文件夹应该可以: <%= render "order_items/order_item_fields", f: order_item %>

如果将_order_item_fields.html.erbviews/order_items移到我的views/orders目录中,页面将呈现,但是我仍然看不到order_item_fields部分中的任何内容。

0 个答案:

没有答案