Skip to content

Commit

Permalink
#dup with unslugged model causes undefined method error
Browse files Browse the repository at this point in the history
In lib/friendly_id/base.rb:252:

```
    def dup
      super.tap { |duplicate| duplicate.slug = nil }
    end
```

However, suppose we have a User with just `friendly_id :login` - no extra slug. #slug= is not defined, and therefore some_user.dup fails.

My patch just makes the dup check if slug= is defined before using it.
  • Loading branch information
saizai committed Jan 23, 2014
1 parent b7d2b0c commit 996a073
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/friendly_id/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def to_param

# Clears slug on duplicate records when calling `dup`.
def dup
super.tap { |duplicate| duplicate.slug = nil }
super.tap { |duplicate| duplicate.slug = nil if duplicate.respond_to?('slug=') }
end
end
end

0 comments on commit 996a073

Please # to comment.