Sha256: c3cb3d67953fd4c354cc16d2d3da18afbb0fd5aa0fab5edb296cb4cdc9e2c31d

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 index_url *args
        polymorphic_url *route_args(route_member(controller_name), *args)
      end

      def 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 + [prefix] + 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.7 lib/puffer/resource/routing.rb
puffer-0.0.6 lib/puffer/resource/routing.rb
puffer-0.0.5 lib/puffer/resource/routing.rb
puffer-0.0.4 lib/puffer/resource/routing.rb
puffer-0.0.3 lib/puffer/resource/routing.rb
puffer-0.0.2 lib/puffer/resource/routing.rb
puffer-0.0.1 lib/puffer/resource/routing.rb