Sha256: 5652a6355cd6c36e70ea7945c6c310526e4f3d900233f76a75614e525ff36598

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

require 'rho/render'
require 'rho/rhosupport'
require 'rho/rhoviewhelpers'

module Rho
  class RhoController

    def default_action
      return Hash['GET','show','PUT','update','POST','update',
        'DELETE','delete'][@request['request-method']] unless @request['id'].nil?
      return Hash['GET','index','POST','create'][@request['request-method']]
    end

    def serve(object_mapping,req,res)
      @request, @response = req, res;
      @object_mapping = object_mapping
      @params = RhoSupport::query_params req
      send req['action'].nil? ? default_action : req['action']
    end

    # Returns true if the request's header contains "XMLHttpRequest".
    def xml_http_request?
      not /XMLHttpRequest/i.match(@request['headers']['X-Requested-With']).nil?
    end
    alias xhr? :xml_http_request?

    def redirect(url_params = {},options = {})
      @response['status'] = options['status'] || 302 
      @response['headers']['Location'] = url_for(url_params)
      @response['message'] = options['message'] || 'Moved temporarily'
      return ''
    end
    
  end # RhoController
end # Rho

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rhodes-0.2.6 lib/rho/rhocontroller.rb
rhodes-0.3.0 lib/rho/rhocontroller.rb
rhodes-framework-1.0.0 lib/rho/rhocontroller.rb
rhodes-framework-1.0.1 lib/rho/rhocontroller.rb
rhodes-framework-1.0.5 lib/rho/rhocontroller.rb
rhodes-framework-1.0.3 lib/rho/rhocontroller.rb
rhodes-framework-1.0.4 lib/rho/rhocontroller.rb
rhodes-framework-1.0.10 lib/rho/rhocontroller.rb
rhodes-framework-1.0.2 lib/rho/rhocontroller.rb
rhodes-framework-1.0.8 lib/rho/rhocontroller.rb
rhodes-framework-1.0.6 lib/rho/rhocontroller.rb
rhodes-framework-1.0.7 lib/rho/rhocontroller.rb
rhodes-framework-1.0.9 lib/rho/rhocontroller.rb
rhodes-framework-1.1.1 lib/rho/rhocontroller.rb
rhodes-framework-1.1.0 lib/rho/rhocontroller.rb