Sha256: 0f37dccc1c55022064e189ad2c1b95129546e3abcd4c9e3b8c57483b51bc9361

Contents?: true

Size: 590 Bytes

Versions: 10

Compression:

Stored size: 590 Bytes

Contents

if defined? ActionController

  ['csv','ods','xlsx'].each do |format|
    ActionController::Renderers.add(format.to_sym) do |data, options|
      if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
        options[:filename] ||= data.klass.name.pluralize
        data = data.send("to_#{format}")
      end

      options[:filename] = options[:filename] ? options[:filename].strip.sub(/\.#{format}$/i,'') : 'data'
      options[:filename] += ".#{format}"
      
      send_data data, type: format.to_sym, disposition: :attachment, filename: options[:filename]
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spreadsheet_architect-5.0.1 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-5.0.0 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-4.2.0 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-4.1.0 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-4.0.1 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-4.0.0 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-3.3.1 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-3.3.0 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-3.2.1 lib/spreadsheet_architect/action_controller_renderers.rb
spreadsheet_architect-3.2.0 lib/spreadsheet_architect/action_controller_renderers.rb