Module: Easy::Api::ControllerMethods::InstanceMethods
- Defined in:
- lib/easy/api/controller_methods.rb
Instance Method Summary collapse
-
#render_format ⇒ Object
Renders the Easy::Api::Result object in either json or html format (can be extended to include other formats).
-
#setup_result ⇒ Object
Initialises a new Easy::Api::Result object (@result) for your controller actions.
Instance Method Details
#render_format ⇒ Object
Renders the Easy::Api::Result object in either json or html format (can be extended to include other formats)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/easy/api/controller_methods.rb', line 5 def render_format respond_to do |format| format.html do render :status => @result.status_code end format.xml do render :xml => @result.to_xml(:root => 'response', :skip_types => true), :status => @result.status_code end format.json do if params[:callback].present? status = 200 content_type = 'application/javascript' else status = @result.status_code content_type = 'application/json' end render :json => @result, :status => status, :callback => params[:callback], :content_type => content_type end end end |
#setup_result ⇒ Object
Initialises a new Easy::Api::Result object (@result) for your controller actions
31 32 33 |
# File 'lib/easy/api/controller_methods.rb', line 31 def setup_result @result = Easy::Api::Result.new end |