Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

#dup with unslugged model causes undefined method error #518

Merged
merged 1 commit into from
Feb 6, 2014

Conversation

saizai
Copy link
Contributor

@saizai saizai commented Jan 23, 2014

In lib/friendly_id/base.rb:252, as introduced in SHA: aa3b4a6:

    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.

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.
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 996a073 on saizai:patch-1 into * on norman:master*.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 996a073 on saizai:patch-1 into * on norman:master*.

@saizai
Copy link
Contributor Author

saizai commented Feb 6, 2014

@norman ?

norman added a commit that referenced this pull request Feb 6, 2014
#dup with unslugged model causes undefined method error
@norman norman merged commit 4e1529b into norman:master Feb 6, 2014
@norman
Copy link
Owner

norman commented Feb 6, 2014

Looks good - thanks!

@saizai
Copy link
Contributor Author

saizai commented Feb 6, 2014

W00t. :-)

@saizai
Copy link
Contributor Author

saizai commented Feb 6, 2014

Could you bump the version # etc so it gets published?

@saizai saizai deleted the patch-1 branch February 7, 2014 20:36
@xymbol
Copy link
Collaborator

xymbol commented Jul 2, 2014

@norman @parndt I suspect this is broken.

Shouldn't we override #dup only when including the FriendlyId::Slugged module? Then, I think we should not invoke #slug= explicitly as that can be changed through configuration.

Will try to reproduce and, file an issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants