File: //usr/local/rvm/gems/default/doc/actionpack-6.1.4.1/ri/ActionController/Renderers/add-c.ri
U:RDoc::AnyMethod[iI"add:ETI"%ActionController::Renderers::add;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"<Adds a new renderer to call within controller actions. ;TI"?A renderer is invoked by passing its name as an option to ;TI"I<tt>AbstractController::Rendering#render</tt>. To create a renderer ;TI"Jpass it a name and a block. The block takes two arguments, the first ;TI"Fis the value paired with its key and the second is the remaining ;TI"(hash of options passed to +render+.;To:RDoc::Markup::BlankLine o;
; [I"Create a csv renderer:;T@o:RDoc::Markup::Verbatim; [I"<ActionController::Renderers.add :csv do |obj, options|
;TI"/ filename = options[:filename] || 'data'
;TI"> str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
;TI"( send_data str, type: Mime[:csv],
;TI"= disposition: "attachment; filename=#{filename}.csv"
;TI" end
;T:@format0o;
; [I"PNote that we used Mime[:csv] for the csv mime type as it comes with Rails. ;TI"EFor a custom renderer, you'll need to register a mime type with ;TI""<tt>Mime::Type.register</tt>.;T@o;
; [I"4To use the csv renderer in a controller action:;T@o;; [I"def show
;TI", @csvable = Csvable.find(params[:id])
;TI" respond_to do |format|
;TI" format.html
;TI"F format.csv { render csv: @csvable, filename: @csvable.name }
;TI" end
;TI"end;T;
0:
@fileI"-lib/action_controller/metal/renderers.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(key, &block);T@0FI"Renderers;TcRDoc::NormalModule00