Add download for articles

This commit is contained in:
Patrick Gansterer 2020-06-22 16:03:32 +02:00
parent b6f5295267
commit 5a9cc811c9
5 changed files with 52 additions and 0 deletions

View file

@ -21,6 +21,12 @@ class ArticlesController < ApplicationController
end
@articles = Article.undeleted.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort)
if request.format.csv?
send_data ArticlesCsv.new(@articles, encoding: 'utf-8').to_csv, filename: 'articles.csv', type: 'text/csv'
return
end
@articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
@articles = @articles.page(params[:page]).per(@per_page)