Sha256: 32c02a42beb63585bc508c4fe16e387a561a0c45a35793f7c43f09c94c37dfb8

Contents?: true

Size: 858 Bytes

Versions: 8

Compression:

Stored size: 858 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

8 entries across 8 versions & 1 rubygems

Version Path
compass-jquery-plugin-0.3.3.1 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.3.0 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.8 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.7 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.7.nil lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.6 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.5 lib/jquery/jquery_json_response.rb
compass-jquery-plugin-0.3.2.4 lib/jquery/jquery_json_response.rb