Sha256: c8d209cefc2c9d731c69d1aa0f2f8dc98de61b9784307de8bb2221e6b91cedda

Contents?: true

Size: 1.91 KB

Versions: 10

Compression:

Stored size: 1.91 KB

Contents

module Devise
  module Controllers
    # Create url helpers to be used with resource/scope configuration. Acts as
    # proxies to the generated routes created by devise.
    # Resource param can be a string or symbol, a class, or an instance object.
    # Example using a :user resource:
    #
    #   new_session_path(:user)      => new_user_session_path
    #   session_path(:user)          => user_session_path
    #   destroy_session_path(:user)  => destroy_user_session_path
    #
    #   new_password_path(:user)     => new_user_password_path
    #   password_path(:user)         => user_password_path
    #   edit_password_path(:user)    => edit_user_password_path
    #
    #   new_confirmation_path(:user) => new_user_confirmation_path
    #   confirmation_path(:user)     => user_confirmation_path
    #
    # Those helpers are added to your ApplicationController.
    module UrlHelpers
      def self.remove_helpers!
        self.instance_methods.map(&:to_s).grep(/_(url|path)$/).each do |method|
          remove_method method
        end
      end

      def self.generate_helpers!(routes=nil)
        routes ||= begin
          mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
          Devise::URL_HELPERS.slice(*mappings)
        end

        routes.each do |module_name, actions|
          [:path, :url].each do |path_or_url|
            actions.each do |action|
              action = action ? "#{action}_" : ""
              method = "#{action}#{module_name}_#{path_or_url}"

              class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
                def #{method}(resource_or_scope, *args)
                  scope = Devise::Mapping.find_scope!(resource_or_scope)
                  send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
                end
              URL_HELPERS
            end
          end
        end
      end

      generate_helpers!(Devise::URL_HELPERS)
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/devise-1.5.4/lib/devise/controllers/url_helpers.rb
devise-1.5.4 lib/devise/controllers/url_helpers.rb
devise-2.0.0.rc lib/devise/controllers/url_helpers.rb
devise-1.5.3 lib/devise/controllers/url_helpers.rb
cloudfoundry-devise-1.5.2 lib/devise/controllers/url_helpers.rb
devise-1.5.2 lib/devise/controllers/url_helpers.rb
devise-1.5.1 lib/devise/controllers/url_helpers.rb
devise-1.5.0 lib/devise/controllers/url_helpers.rb
devise-1.5.0.rc1 lib/devise/controllers/url_helpers.rb
devise-1.4.9 lib/devise/controllers/url_helpers.rb