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

Reserved words validation fails even if other valid slug candidates exist. #536

Closed
reichertm opened this issue Mar 17, 2014 · 7 comments
Closed

Comments

@reichertm
Copy link

friendly_id 5.0.2, rails 4.1.0.rc1, ruby 2.1.0

A validation error 'Friendly is reserved' is being thrown if the first slug candidate happens to be a reserved word, even if the next slug candidate is valid. Perhaps all the slug candidates should be tried before the 'reserved' error is thrown.

e.g.
Model 'User' with fields 'name' and 'location' has the following slug definition:

friendly_id :slug_candidates, use: [:slugged, :history]
def slug_candidates
   [:name, [:name, :location]]
end

The reserved words contains 'new'

When you try to create a user with name 'new' and location 'ny' the error gets thrown. Perhaps validation should pass creating slug 'new-ny' or such.

@evandrodp
Copy link

+1

@norman norman modified the milestone: 5.0 May 29, 2014
@norman norman added the Bug label May 29, 2014
@gottfrois
Copy link

+1

@xymbol
Copy link
Collaborator

xymbol commented Jul 17, 2014

We're looking at this issue, in the context of other changes and improvements. Please keep subscribed to this issue if you're interested in updates.

@mszyndel
Copy link

I would love to provide a patch for that, it is ok @xymbol @reichertm @norman or are you already working on this?

@xymbol
Copy link
Collaborator

xymbol commented Jul 21, 2014

@hajder Please, feel free to do so. Even if something didn't play well with other changes, we can either get the patch fixed, reuse parts of it or, at least, add a note with the credits. And yes, we've been working on this. Thanks!

@mszyndel
Copy link

Ok, so I know how to fix that problem on the conceptual level but not sure about the code. Maybe someone can help out with that? (@xymbol @norman)

In FriendlyId::Reserved a validation is added for slugged model which causes current problem.
My solution would be to override FriendlyId::Candidates#wanted? (which is a private method) to check if slug candidate is on reserved words list (and return false if it is). I don't really know however how to change this method from the FriendlyId::Reserved module.

@norman
Copy link
Owner

norman commented Dec 17, 2014

This is now implemented in 23117f7.

@norman norman closed this as completed Dec 17, 2014
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants