1

我有一张发票表格。为了消除大量输入,用户需要输入发票属性,然后单击按钮复制第一条记录,更改几个属性,然后一次保存所有记录。Excel 风格。帮助?

<% form_for @invoice, :html => { :multipart => true } do |f| %>
   <%= f.error_messages %>


<table class="ExcelTable2007">
     <tr>      
       <th class="heading">PO #<font color="red"> *</font></th>
       <th class="heading">Invoice #</th>
       <th class="heading">"Bill To" is Correct</th>
       <th class="heading">Invoice Date</th>
       <th class="heading">Date Received</th>
       <th class="heading">AP Clerk Note</th>
       <th class="heading">Division</th>
       <th class="heading">GR Approver</th>
       <th class="heading">GR Alternate Approver</th>
       <th class="heading">Invoice Attachment</th>
     </tr>  
     <tr>      
       <td class="heading"><%= f.text_field :po_number, :size => 10 %></td>
       <td class="heading"><%= f.text_field :invoice_number, :size => 10 %></td>
       <td class="heading"><%= f.check_box :bill_to_address %></td>
       <td class="heading"><%= f.calendar_date_select "invoice_date", :time => false, :size => 12 %></td>
       <td class="heading"><%= f.calendar_date_select "date_received", :time => false, :size => 12 %></td>
       <td class="heading"><%= f.text_field :clerk_note %></td>
       <td class="heading"><%= f.collection_select :division_id, Division.active.order(:division), :id, :division, :include_blank => true %></td>
       <td class="heading"><%= f.collection_select :approver_username, Aduser.order(:last_name, :first_name), :username, :fullname, :include_blank => true %></td>
       <td class="heading"><%= f.collection_select :alternate_approver_username, Aduser.order(:last_name, :first_name), :username, :fullname, :include_blank => true %></td>
       <td class="heading"><%= f.file_field :attachment %></td>
      </tr>
    </p>
</table>
&emsp;&emsp;&emsp;&emsp;<%= link_to "Add Invoice", clone_invoice_url(@invoice) %>
  <br>
  <br>

  <div class="actions">
    <%= f.submit "Submit" %>
  </div>
  </p>
<% end %>

我尝试了以下操作,但收到了无效的真实性令牌:

def clone_invoice
  @invoice = Invoice.find(params[:id]).dup
  @invoice.save
end

谁能帮我?提前致谢!

4

1 回答 1

0

试试这个。

def clone_invoice
  @invoice = Invoice.find(params[:id])
  @new_invoice = @invoice.dup
end

如果您的发票有附件,那么您还需要复制该附件。

dupfile(@invoice.attachement.to_s, @new_invoice.attachment.to_s)

在您的路线文件中,尝试

match 'invoices/:id/invoice_clone' => "invoices#clone_invoice", :as => "invoice_clone"

然后在你的link_to,改变clone_invoice_urlinvoice_clone_path

于 2013-01-31T20:44:41.967 回答