가져 오기 전에 가져 오기 또는 미리보기를 할 수있는 CSV 파일을 업로드 할 수있는 양식을 만들려고합니다.레일 3.2 또는 4.x 미리보기 용 양식/파일 제출
<%= form_for(@contact_import, :remote => true) do |f| %>
<% if @contact_import.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@contact_import.errors.count, "error") %> prohibited this import from completing:</h2>
<ul>
<% @contact_import.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.file_field :file %>
</div>
<%= f.submit "Import" %>
<%= f.submit "Preview", :name => 'preview' %>
을 내 컨트롤러 : 내 양식에
내가 가진
def create
@contact_import = ContactImport.new(params[:contact_import])
if params[:preview]
logger.debug "Let's preview the contacts:" + params.inspect
@contacts = @contact_import.update_preview
@contact_attributes = ContactImport.mapping_attributes
#I should now update the preview div
else
logger.debug("Got the commit" + params.inspect)
if @contact_import.save
redirect_to root_url, notice: "Imported contacts successfully."
else
render :new
end
end
end
은 어떻게 CSV는 파일을 업로드하여 미리보기 연락처를 표시하는보기를 업데이트 할 수 있습니까?
참고 : 현재 CVS 파일 처리는 모델에 있으므로 생략되었습니다.
나는 그가 원격 호출을하고 있다고 생각하는데,이 경우에는 렌더링만으로는 작동하지 않는다. – Noz
죄송합니다 - 게시했을 때 알리지 않았습니다. 파일 필드가있는 원격 양식을 작성하려면 훨씬 더 많은 작업이 필요합니다. https://github.com/JangoSteve/remotipart와 같은 보석을보고 싶을 수도 있습니다. 그러나, 나는 그것이 레일 3.2에서 작동하는지 확신 할 수 없다. – Swards