Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/ar_dumper_controller.rb
Constant Summary collapse
- @@dumper_target =
:tmp_file
Instance Method Summary collapse
-
#send_file_dump(format, klass, send_options = {}, dump_options = {}) ⇒ Object
send a dumped file Options are: *
klass
- the active record to use.
Instance Method Details
#send_file_dump(format, klass, send_options = {}, dump_options = {}) ⇒ Object
send a dumped file Options are:
-
klass
- the active record to use. Animal or Contact or Author or Tumama -
send_options
send_options include send_file options such as:type
and:disposition
-
dump_options
options to send to the dumper. These options are in ArDumper.dump_to_csv -
:find
- a map of the finder options passed to find. For example, + => [‘features.hair = ?’, ‘blonde’], :include => :features + -
:header
- when a hash is specified, maps the field name to the header name. For example => ‘COL A’, :b => ‘COL B’ would print ‘COL A’, ‘COL B’when an array is specified uses this instead of the fields when true or by default prints the fields when false does not include a header
-
:csv
- any options to pass to csv parser. Example + :csv => => “t” + -
:page_size
- the page size to use. Defaults to dumper_page_size or 50
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ar_dumper_controller.rb', line 20 def send_file_dump(format, klass, ={}, ={}) #use the base name of the dump file name if specified [:filename] ||= File.basename([:filename]) if [:filename] #never delete the file [:delete_file] = false #use temporary files unless otherwise specified [:target_type]||= @@dumper_target #send_options[:type] = 'application/xml; charset=utf-8;' if [:type].nil? && [:disposition] == 'inline' [:type] = case format.to_sym when :xml then 'application/xml; charset=utf-8;' when :csv then 'application/csv; charset=utf-8;' when :yml then 'text/html; charset=utf-8;' end end target = klass.dumper(format, ) if [:target_type] == :string send_data(target, ) else send_file(target, ) end end |