Skip to content

Instantly share code, notes, and snippets.

@tabishiqbal
Created September 17, 2016 23:55
Show Gist options
  • Save tabishiqbal/99c3598f7d0b98b6fcba15b325a9c22b to your computer and use it in GitHub Desktop.
Save tabishiqbal/99c3598f7d0b98b6fcba15b325a9c22b to your computer and use it in GitHub Desktop.
Products Import
-- views/settings/_products.html.erb
<div class="ibox-title">
<h5>Import Products</h5>
<a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
<a class=""><%= link_to "", products_path, class: "fa fa-times" %></a>
</div>
<div class="box-content">
<p>A CSV file can be used to import products. The first row should be the column name. The following columns are allowed.</p>
<ul>
<li>Vendor Id</li>
<li>Model Number</li>
<li>Description</li>
<li>List Price</li>
</ul>
<div class="form-group">
<%= form_tag import_products_path, multipart: true do %>
<%= file_field_tag :file %><br/>
<%= submit_tag "Import", class: "btn btn-w-m btn-primary" %>
<% end %>
</div>
</div>
def import
Product.import(params[:file])
redirect_to products_path, :flash => { :success => "Products Imported"}
end
resources :products do
collection { post :import }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment