Module: Devise::Controllers::UrlHelpers

Defined in:
lib/devise/better_routes.rb

Class Method Summary collapse

Class Method Details

.override_registration_helpers!(registration_routes = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/devise/better_routes.rb', line 9

def self.override_registration_helpers!(registration_routes = nil)
  helper_mappings = {
    new_registration: 'new_#{scope}',
    edit_registration: 'edit_#{current_resource_name}',
    cancel_registration: 'cancel_#{current_resource_name}'
  }
  [:path, :url].each do |path_or_url|
    class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
      def registration_#{path_or_url}(resource_or_scope, *args)
        scope = Devise::Mapping.find_scope!(resource_or_scope)
        current_resource_name = _devise_path_name(scope, "current_\#{scope}")
        if respond_to?(:controller_name) && controller_name == current_resource_name.pluralize
          send("\#{current_resource_name}_#{path_or_url}", *args)
        else
          send("\#{scope.to_s.pluralize}_#{path_or_url}", *args)
        end
      end
    URL_HELPERS
    helper_mappings.each do |old_name, new_name|
      method = "#{old_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)
          current_resource_name = _devise_path_name(scope, "current_\#{scope}")
          send("#{new_name}_#{path_or_url}", *args)
        end
      URL_HELPERS
    end
  end
end

.run_generate_hooks!Object



41
42
43
# File 'lib/devise/better_routes.rb', line 41

def self.run_generate_hooks!
  self.override_registration_helpers!(Devise::URL_HELPERS[:registration])
end