Sha256: 4a2bc53d6085bc107fa25f672487e4fce9f512f1845bf3b5865af5376e8fd245

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

module Puffer
  class Resource
    module Routing

      include ActionController::UrlFor
      include Rails.application.routes.url_helpers

      def collection_url *args
        polymorphic_url *route_args(route_member(model), *args)
      end

      def member_url *args
        suggest = args.shift if args.first.is_a? ActiveRecord::Base
        polymorphic_url *route_args(route_member(suggest), *args)
      end

      def new_url *args
        new_polymorphic_url *route_args(controller_name.singularize, *args)
      end

      def edit_url *args
        suggest = args.shift if args.first.is_a? ActiveRecord::Base
        edit_polymorphic_url *route_args(route_member(suggest), *args)
      end

      def route_args *args
        options = args.extract_options!
        resource = args.shift
        return args + [namespace] + ancestors.map(&:route_member) + [resource], options
      end

      def route_member suggest = nil
        plural? ? (suggest || member) : controller_name.singularize
      end

      def default_url_options *args
        Puffer::Base.default_url_options(*args)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puffer-0.0.26 lib/puffer/resource/routing.rb
puffer-0.0.25 lib/puffer/resource/routing.rb
puffer-0.0.24 lib/puffer/resource/routing.rb
puffer-0.0.23 lib/puffer/resource/routing.rb
puffer-0.0.22 lib/puffer/resource/routing.rb
puffer-0.0.21 lib/puffer/resource/routing.rb
puffer-0.0.20 lib/puffer/resource/routing.rb