Created
September 17, 2016 23:55
-
-
Save tabishiqbal/99c3598f7d0b98b6fcba15b325a9c22b to your computer and use it in GitHub Desktop.
Products Import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import | |
Product.import(params[:file]) | |
redirect_to products_path, :flash => { :success => "Products Imported"} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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