Sha256: 627e093d0926733a4a16c8c4e5fad004cdbb6020592d09b7a5b20aab461152c4

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

module Rad::ControllerRoutingHelper
  inherit Rad::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, content
  end    
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.5 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.4 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.3 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.2 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.1 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.2.0 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.30 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.29 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.28 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.27 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.26 lib/rad/web/_router/controller_routing_helper.rb
rad_core-0.0.25 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.24 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.23 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.22 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.21 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.20 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.19 lib/rad/core_web/_router/controller_routing_helper.rb
rad_core-0.0.18 lib/rad/core_web/_router/controller_routing_helper.rb