0

朋友们,我有一个模型订单,里面有很多细节。我正在使用茧宝石生成表单。他们渲染好但没有保存。我单击按钮保存,没有任何反应,rails 控制台什么也没显示。名为 detail_fields 的默认编辑表单可以毫无问题地保存。但是我必须创建一个名为 detail_fields_dev 的文件,而这个文件不起作用。有人可以帮忙吗?

路线.rb

resources :details
resources :orders
get '/orders/:id/devolucao' => 'orders#devolucao' , as: 'devolucao_order'
put '/orders/:id' => 'orders#update'
patch '/orders/:id' => 'orders#update'

orders_controller,没问题,使用默认的 rails 代码。我创建了这个动作来调用 detail_fields_dev 表单:

def devolucao
# @order = Order.find(params[:id])
end

细节参数也可以:

def order_params
  params.require(:order).permit(:customer_id, :valor_total,   :valor_total_dev, :item_total, :item_total_dev,:tipo,:descontado,:order_num, details_attributes: [:id,:order_id, :cod_produto, :desc_produto, :cod_cor, :desc_cor, :desc_tamanho,:preco,:quantidade,:quantidade_dev,:total, :total_dev,:barcode, :_destroy])
end

订单视图:

_form_devolucao.html.erb

  <%= simple_form_for(@order) do |f| %>
    <%= f.error_notification %>
    <div class="form-inputs form_fixed">
      <%= f.input :customer, :as => :hidden %>
      <%= f.input :tipo, :as => :hidden %>
      <%= f.input :descontado, :as => :hidden %>
      <%= f.input :valor_total, :as => :hidden %>
      <%= f.input :item_total, :as => :hidden %>
      <%= f.input :order_num, :as => :hidden %>
      <div class="row">
          <form action="#" method="post">
            <div class="small-6 medium-3 columns leitor_dev">
                      Código de barras
                      (<a href="http://zxing.appspot.com/scan?ret=http://www.auere.com.br/testes/barcode.php?codigo={CODE}">Leitor</a>):
                      <input class = "cod_barras_dev" type="text" name="cod_barras_dev" value="" />
          </div>
          </form>
        <div class="small-5 columns end not_found">
          <span class="not_found">Produto não existe neste pedido!</span>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="small-12 columns">
            <hr/>
                <div id="details">
                  <%= f.simple_fields_for :details do |detail| %>
                       <%= render partial: "orders/detail_fields_dev", locals: {f: detail} %>
                     <% end %>
                </div>
      <hr/>
      </div>
    </div>
    <div class="row">
      <div class="small-12 columns">
        <div class="form-actions container">
          <%= link_to_add_association '+ ítens', f, :details, data: {"association-insertion-method" => :before, "association-insertion-node" => ".container  " },:class => "button tiny radius add" %>
          <br />
          <br />
          <br />
        </div>
      </div>
    </div>
    <div class="row">
      <div class="small-6 medium-2 columns">
        <%= f.button :submit, "Salvar" %>
      </div>
      <div class="small-6 medium-2 columns end">
        <%= link_to 'Cancelar', orders_path, :class => "button alert"%>

      </div>
    </div>
  <% end %>

以及部分订单/detail_fields_dev.html.erb

<div class="nested-fields">
    <div class="row listCod" data-cod="<%= f.object.barcode %>">
    <div class="small-6 columns show-for-small-only">
      <%= f.input :barcode, label: "Cod Barras", input_html: { class: 'barcode_ror_dev' } %>
    </div>
      <%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror_dev' } %>
      <div class="show-for-medium-up small-2 columns">
        <%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror_dev' } %>
      </div>
      <%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror_dev' } %>
      <%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror_dev' } %>
      <div class="small-2 show-for-medium-up columns">
        <%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror_dev' } %>
      </div>
      <div class="small-2 show-for-medium-up columns">
          <%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror_dev' } %>
      </div>
      <div class="small-2 show-for-medium-up columns">
          <%= f.input :preco,label: "Preço",input_html: { class: 'preco_ror_dev' } %>
      </div>
      <div class="small-6 medium-2 columns">
          <%= f.input :quantidade_dev,label: "Qtd Dev", input_html: { class: 'quantidade_ror_dev' } %>
      </div>
      <div class="show-for-medium-up medium-2 columns end">
          <%= f.input :total_dev,label: "Total Dev",input_html: { class: 'total_ror_dev' } %>
      </div>
      <div class="small-1 columns end">
        <%= link_to_remove_association "-", f, :class => "button tiny alert remove"%>
      </div>
    </div>
</div>

输出:

!(http://imgur.com/kVPpwY6

4

0 回答 0