Exporting Data to Excel file in Rails
There are two ways of doing the same thing first is to use the gem to_xls-rails and another is without gem I am gonna explain both approaches: Approach 1 : Using gem 'to_xls-rails' 1. ) bundle install 2.)Your Controller def index @posts = Post.all respond_to do |format| format.html # don't forget if you pass html format.xls { send_data(@posts.to_xls) } end end 3.)Your View <%= link_to 'Excel Download', posts_path(:format => :xls) %> 4.)config/initializers/mime_type.rb Mime::Type.register "application/vnd.ms-excel", :xls Another way or standard way without any gem