Sha256: 20c4c0070dbc6a06d2a58ef9dc19930cd57ce34c97b4f34baab27962f3cbbdf7

Contents?: true

Size: 879 Bytes

Versions: 4

Compression:

Stored size: 879 Bytes

Contents

module ActionController
  class Base
  
    # From http://paydrotalks.com/posts/45-standard-json-response-for-rails-and-jquery
    
    def render_json_response(type, hash)
      unless [ :ok, :redirect, :error ].include?(type)
        raise "Invalid json response type: #{type}"
      end
    
      # To keep the structure consistent, we'll build the json 
      # structure with the default properties.
      #
      # This will also help other developers understand what 
      # is returned by the server by looking at this method.
      default_json_structure = { 
        :status => type, 
        :html => nil, 
         :message => nil, 
        :to => nil }.merge(hash)
     
      render_options = {:json => default_json_structure}  
      render_options[:status] = 400 if type == :error
    
      render(render_options)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
compass-jquery-plugin-0.3.2.3 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.2 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.1 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.0 lib/jquery/jquery_json_response.rb