Sha256: a378a16e32e6e68a58bd9c39395c1ca0610089f6176a0986856596467d98399e

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Rad
  module CoreRoutingHelper
    inject router: :router
    
    delegate :url_for, :url_for_path, :persist_params, :persist_params?, :dont_persist_params, to: :router 
    
    def default_path options = {}
      url_for_path config.default_path!, options.merge(url_root: false)
    end

    def return_to_path options = {}
      dont_persist_params do 
        path = params[:_return_to] || workspace.request.session['return_to'] || config.default_path!
        url_for_path path, options.merge(url_root: false)
      end
    end
    
    def parse_routing_arguments *args
      params = args.extract_options!
      raise "invalid usage!" unless args.size <= 1
      if args.size == 1
        raise "duplicate :id pameter!" if params.include?(:id) or params.include?('id')
        params[:id] = args.first.to_param
      end
      params      
    end
    
    protected
      def method_missing m, *args, &block
        m = m.to_s
        if m =~ /_path$/
          params = parse_routing_arguments(*args)
          klass, method = router.encode_method m
          
          url_for klass, method, params
        else
          super m.to_sym, *args, &block
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/router/core/core_routing_helper.rb