Class: Padrino::Responders::Jsend
- Includes:
- Padrino::Response::StatusCodes
- Defined in:
- lib/padrino-response/responders/jsend.rb
Constant Summary
Constants included from Padrino::Response::StatusCodes
Padrino::Response::StatusCodes::STATUS_CODES, Padrino::Response::StatusCodes::SYMBOL_TO_STATUS_CODE
Instance Attribute Summary collapse
-
#class ⇒ Object
Returns the value of attribute class.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #default ⇒ Object
- #delete ⇒ Object
-
#initialize ⇒ Jsend
constructor
A new instance of Jsend.
- #jsend? ⇒ Boolean
- #put_or_post(message_type, error_detour) ⇒ Object
Methods included from Padrino::Response::StatusCodes
Methods inherited from Default
#action_name, #api_request, #controller_name, #human_model_name, #layout, #location, #message, #notify, #post, #put, #redirect, #request, #respond, #set_status, #try_render, #valid?
Constructor Details
#initialize ⇒ Jsend
Returns a new instance of Jsend.
7 8 9 |
# File 'lib/padrino-response/responders/jsend.rb', line 7 def initialize @options = {} end |
Instance Attribute Details
#class ⇒ Object
Returns the value of attribute class.
5 6 7 |
# File 'lib/padrino-response/responders/jsend.rb', line 5 def class @class end |
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/padrino-response/responders/jsend.rb', line 5 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/padrino-response/responders/jsend.rb', line 5 def @options end |
Instance Method Details
#default ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/padrino-response/responders/jsend.rb', line 79 def default if location if request.xhr? {:status => :success, :data => { :redirect => location } }.to_json else redirect location end else try_render end end |
#delete ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/padrino-response/responders/jsend.rb', line 54 def delete = (:destroy) if request.xhr? ajax_obj = { :status => :success, :data => { :message => } } end if location if request.xhr? ajax_obj[:data][:redirect] = location return ajax_obj.to_json else notify(:notice, ) redirect location end else try_render end end |
#jsend? ⇒ Boolean
11 12 13 |
# File 'lib/padrino-response/responders/jsend.rb', line 11 def jsend? return true end |
#put_or_post(message_type, error_detour) ⇒ Object
15 16 17 18 19 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 50 51 52 |
# File 'lib/padrino-response/responders/jsend.rb', line 15 def put_or_post(, error_detour) = ( ) if valid? if request.xhr? ajax_obj = { :status => :success, :data => { object.class.to_s.singularize.downcase => object } } end if location if request.xhr? ajax_obj[:data][:redirect] = location return ajax_obj.to_json else notify(:notice, ) redirect location end else try_render end else if request.xhr? ajax_obj = { :status => :fail, :data => { :errors => object.errors } } ajax_obj[:data][:redirect] = location if location return ajax_obj.to_json else notify(:error, ) try_render error_detour end end end |