Module: JSend::Rails::Controller
- Defined in:
- lib/jsend-rails/controller.rb
Instance Method Summary collapse
-
#render_jsend(options_or_status) ⇒ Object
Render a jsend response.
Instance Method Details
#render_jsend(options_or_status) ⇒ Object
Render a jsend response
By default, renders using render json:
If you need to tweak rendering options, for example to render json inside a <textarea> to fix cranky browsers, pass a :render hash, like:
render_jsend {success: {}, render: {as: :text, layout: ‘json’}}
In the :render, the :as key will be used to control the rendering format. Any other options will be passed directly to the render call. The example above will result in the following call to render:
render text: {…}, layout: ‘json’
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jsend-rails/controller.rb', line 19 def render_jsend() = if .is_a?(Hash) = [:render] || {} format = .delete(:as) || :json [format] = Envelope.compute().to_json else {json: Envelope.compute()} end render end |