Skip to content

Commit

Permalink
Url helpers should rely find_scope!
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 19, 2010
1 parent 04ce9d1 commit b4183cb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Expand Up @@ -8,6 +8,7 @@

* bug fix
* Accept path prefix not starting with slash
* url helpers should rely on find_scope!

== 0.8.2

Expand Down
10 changes: 1 addition & 9 deletions lib/devise/controllers/url_helpers.rb
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/devise/mapping.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b4183cb

Please sign in to comment.