Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Create Shorter Conflict Slugs and Recreate Slugs on Update #576

Closed
harshamv opened this issue Jun 27, 2014 · 3 comments
Closed

Create Shorter Conflict Slugs and Recreate Slugs on Update #576

harshamv opened this issue Jun 27, 2014 · 3 comments

Comments

@harshamv
Copy link

If i have a conflicting slug it generates a very long slug as follows

Explore explore
Explore explore-7a8411ac-5af5-41a3-ab08-d32387679f2b

Is there a way i can just create 'explore-1', 'explore-2' etc.

Other option is i want to have a shorter slug generator like the following

candidates.first + friendly_id_config.sequence_separator + SecureRandom.hex(3)

How can i create a Initialization to allow this across all models?
Also how can i recreate the slug on updating a record in the model?

@xymbol
Copy link
Collaborator

xymbol commented Jun 27, 2014

@harshamv This is how friendly_id used to work, was lengthly discussed and, changed for a very good reason. You can always provide, say, 10 numbered candidates, and use that. This is not a general recommended solution but, might be valid in the context of your app.

@xymbol xymbol closed this as completed Jun 27, 2014
@harshamv
Copy link
Author

how can get a a fixed length of the hec value. also would like to read about the discussion and may have a valid point as well. did it happen on github discussion and can you share a link?

@xymbol
Copy link
Collaborator

xymbol commented Jun 30, 2014

@harshamv Don't understand your question. Please provide an example or test. As for your original question, this might work:

class Post < ActiveRecord::Base
  extend FriendlyId
  friendly_id :candidates, use: :slugged

  def candidates_with_sequence
    2.upto(10).inject([title]) { |m, o| m << "%s %d" % [title, o] }
  end
  alias_method :candidates, :candidates_with_sequence

  def candidates_with_hash
    [title, "%s %s" % [title, SecureRandom.hex(3)]]
  end
end

If any of your candidates are available, you'd still get the UUID-based conflict resolution functionality -- which is a good thing.

Re the discussion, this library has years of experience around this particular problem. We can't recall every discussion, how it originated and got resolved. This is the actual commit that introduced the current UUID-based sequencing. There's even a brief explanation in the README file.

Have you checked that already?

@dounanhu dounanhu mentioned this issue Aug 16, 2014
onerinas pushed a commit to onerinas/friendly_id that referenced this issue Jun 20, 2015
Read me update with code for previously used numeric sequence

Suggestion reference: norman#602 (comment)

Code reference: norman#576 (comment)
This was referenced Jun 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants