Sha256: c569fdbf5960da0da441db3bd1e652dbd71b02466f7ea665109ae2e0f7ce667a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module MakeRestful::Rendering

  private

  ## Rendering
  def render(*args, &block)
    options = args.last.is_a?(Hash) && args.last.extractable_options? ? args.last : {}
    template_present = template_exists?([params[:controller], params[:action]].join('/'))
    options[:load_template] = true if options[:load_template].nil?
    cleaned_options = options.reject{ |k,v| [:load_template, :status].include?(k) }

    super and return if (( template_present && options[:load_template]) || cleaned_options.present? ) && allowed_formats.allowed?(formats)

    # Set the response from the chain
    response = @response || @instance || @collection

    respond_to do |format|
      format.json { super json: response, status: @status, callback: ( params[:callback] if allowed_formats.allowed? :jsonp )} if allowed_formats.allowed? :json, :jsonp
      format.xml  { super xml:  response, status: @status } if allowed_formats.allowed? :xml
      format.any  do
        head @status and return if @status
        super
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
make_restful-0.1.4 lib/make_restful/rendering.rb