XlsxtreamRails
Xlsx stream download for rails.
Installation
Add this line to your application's Gemfile:
gem "xlsxtream_rails"And then execute:
$ bundleOr install it yourself as:
$ gem install xlsxtream_railsController
Set your instance variables in your controller and configure the response if needed:
class PostsController < ApplicationController
def index
@posts = Post.all
respond_to do |format|
format.xlsx { render xlsx: @posts }
end
end
endModel
Add xlsx_columns method for model:
class Post < ApplicationRecord
def xlsx_columns
[:id, :title, :body]
end
endor
class Post < ApplicationRecord
belongs_to :category
def xlsx_columns
[
[:category, category.name],
:title,
:body
]
end
endThis gem is inspired by the following
License
The gem is available as open source under the terms of the MIT License.