# ActiveModel::Exporters [![Build Status](https://travis-ci.org/alejandrogutierrez/active_model_exporters.png?branch=master)](https://travis-ci.org/alejandrogutierrez/active_model_exporters) [![Coverage Status](https://coveralls.io/repos/alejandrogutierrez/active_model_exporters/badge.png)](https://coveralls.io/r/alejandrogutierrez/active_model_exporters) `ActiveModel::Exporters` aims to provide an easy way to export collections of `ActiveModel` or `ActiveRecord` objects. It's based on object-oriented development and inspired on [active_model_serializers](https://github.com/rails-api/active_model_serializers). ## Installation Add this line to your Gemfile: ```ruby gem 'active_model_exporters' ``` Run the bundle command to install it. ## Getting started Generate an exporter in `app/exporters/post_exporter.rb`: ```ruby class PostExporter < ActiveModel::Exporter attributes :id, :name, :email end ``` In your controller: ```ruby class PostsController < ApplicationController def index @posts = Post.all respond_to do |format| format.csv { render csv: @posts } end end end ``` ### Custom exporter To specify a custom exporter for an object, you can do the next: ```ruby render csv: @posts, exporter: OtherPostExporter ``` ### Computed properties As `ActiveModel::Serializers` does, you can access the object being exported as `object`. ```ruby class PostExporter < ActiveModel::Exporter attributes :id, :name, :full_name def full_name "#{object.name} #{object.last_name}" end end ``` ## Contributing New feature or code refactoring? Submit a pull request that implements it. Don't forget to write your tests and include a CHANGELOG with your updates. Thank you :heart: