Skip to content
Browse files

Url helpers should rely find_scope!

  • Loading branch information...
1 parent 04ce9d1 commit b4183cbaa234eeb623113c5e8884363c7840ca62 @josevalim josevalim committed Jan 19, 2010
Showing with 5 additions and 11 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +1 −9 lib/devise/controllers/url_helpers.rb
  3. +3 −2 lib/devise/mapping.rb
View
1 CHANGELOG.rdoc
@@ -8,6 +8,7 @@
* bug fix
* Accept path prefix not starting with slash
+ * url helpers should rely on find_scope!
== 0.8.2
View
10 lib/devise/controllers/url_helpers.rb
@@ -28,15 +28,7 @@ module UrlHelpers
actions.each do |action|
class_eval <<-URL_HELPERS
def #{action}#{module_name}_#{path_or_url}(resource, *args)
- resource = case resource
- when Symbol, String
- resource
- when Class
- resource.name.underscore
- else
- resource.class.name.underscore
- end
-
+ resource = Devise::Mapping.find_scope!(resource)
send("#{action}\#{resource}_#{module_name}_#{path_or_url}", *args)
end
URL_HELPERS
View
5 lib/devise/mapping.rb
@@ -42,7 +42,8 @@ def self.find_by_class(klass)
# Receives an object and find a scope for it. If a scope cannot be found,
# raises an error. If a symbol is given, it's considered to be the scope.
def self.find_scope!(duck)
- if duck.is_a?(Symbol)
+ case duck
+ when String, Symbol
duck
else
klass = duck.is_a?(Class) ? duck : duck.class
@@ -103,7 +104,7 @@ def raw_path
def parsed_path
returning raw_path do |path|
self.class.default_url_options.each do |key, value|
- path.gsub!(key.inspect, value.to_s)
+ path.gsub!(key.inspect, value.to_param)
end
end
end

0 comments on commit b4183cb

Please sign in to comment.
Something went wrong with that request. Please try again.