Sha256: 210de7261bb2cc9e84158d6066ba156e8263de4812daa6926d4fbaf8294f4b25

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module Rad
  module ControllerRoutingHelper
    inherit AbstractRoutingHelper
    
    module ClassMethods
      
      # 
      # persist_params controller filters
      # 
      def persist_params *args
        if args.empty?
          before :persist_params
        elsif args.first.is_a? Hash
          before :persist_params, args.first
        else
          before :persist_params, only: args.first
        end
      end
    end
    
    # 
    # redirect_to
    # 
    def redirect_to *args
      params, response = workspace.params, workspace.response
      params.format.must_be.in 'html', 'js'

      if url = special_url(args.first)
        args.size.must_be <= 1
      else
        url = url_for(*args)
      end
      content_type = Mime[params.format]

      content = if params.format == 'js'
        response.set!(
          status: :ok, 
          content_type: content_type
        )
        
        "window.location = '#{url}';"
      else
        response.set!(
          status: :redirect, 
          content_type: content_type
        )
        response.headers['Location'] = url                        
        
        %(<html><body>You are being <a href="#{url.html_escape if url}">redirected</a>.</body></html>)
      end
      
      # Flash need to know if we using redirect
      keep_flash!
      
      throw :halt_render, content
    end    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/integration/router/controller_routing_helper.rb