def render_csv(filename = nil, view_name = nil)

      filename ||= params[:action]
      view_name ||= params[:action]
      filename.downcase!
      filename += '.csv' unless filename[-4..-1] == '.csv'

      headers['Content-Type'] = 'text/csv'
      headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""

      render view_name, layout: false
    end
def render_csv(filename = nil, view_name = nil)

      filename ||= params[:action]
      view_name ||= params[:action]
      filename.downcase!
      filename += '.csv' unless filename[-4..-1] == '.csv'

      headers['Content-Type'] = 'text/csv'
      headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""

      render view_name, layout: false
    end
Renders the view as a CSV file.

 Set the +filename+ you would like to provide to the client, or leave it nil to use the action name.
 Set the +view_name+ you would like to render, or leave it nil to use the action name.