我有一个发票表格。 为了消除大量的输入,用户需要输入发票属性,然后单击按钮复制第一条记录,更改几个属性,然后一次保存所有记录。 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>
    <%= 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
谁能帮我? 提前感谢!
试试这个。
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_url
更改为invoice_clone_path