Reputation: 6026
http://railscasts.com/episodes/362-exporting-csv-and-excel
I'm following that railcast episode. It's working perfect but while I export to csv file that unable add .csv extension means that it's store like products not as products.csv.
I want to store like products.csv how can do that means how can i add extension during saving that file that take automatically add extension during save csv file.
Update
When I export CSV file then I will open popup like above image. but I want products.csv in the Name:
Update 2
Controller
respond_to do |format|
format.html
format.csv { send_data @customers.to_csv }
format.xls
end
View
<%= link_to "CSV", "/admin/partners?id=#{params[:id]}&start_date=#{params[:start_date]}&end_date=#{params[:end_date]}&format=csv" %>
<%= link_to "Excel", "/admin/partners?id=#{params[:id]}&start_date=#{params[:start_date]}&end_date=#{params[:end_date]}&format=xls" %>
Thanks
Upvotes: 0
Views: 948
Reputation: 13842
Controller:
respond_to do |format|
format.csv { send_data @report.to_csv, filename: @report.name + ".csv"} #to export csv
end
In the view
<%= link_to 'CSV', report_path(report, format: :csv)%>
Upvotes: 4
Reputation: 4053
try this, it should work.
<%= link_to "Products CSV", products_path(:format => 'csv') %>
def index
products = Product.all
respond_to do |format|
format.csv do
send_data products.to_csv
end
end
end
Upvotes: 2