norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.15k stars 591 forks source link

Friendly Id Rails 4 url includes extra characters #433

Closed redbush closed 11 years ago

redbush commented 11 years ago

Hi,

I'm using friendly_id on Rails 4: gem "friendly_id", "~> 5.0.0.alpha.1"

For some reason after adding a couple articles in my production site I get a url like the following: http://www.painterprofessions.com/articles/pdca-forms-strategic-alliance-with-painter-professions-2bc08962-b3dd-4f29-b2e6-244710c86106

My model looks like the following:

class Article < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: [:slugged, :history]

  validates_presence_of :name, :content

  self.per_page = 10

  def self.get_recent_three
    Article.order("created_at DESC").limit(3)
  end

  def should_generate_new_friendly_id?
    true
  end
end

Please advise.

norman commented 11 years ago

FriendlyId 5 is fairly different from 4, the README and docs explain the reason why it's using UUIDs rather than sequences now.

You also don't need the should_generate_new_friendly_id? method any more with version 5; the default behavior has changed. When you want to generate a new slug you simply set the slug field to nil, otherwise it will keep the old one.

You may also want to use 5.0.0.beta1 which was released yesterday and has a few fixes since the alpha release.

norman commented 11 years ago

You also don't need the should_generate_new_friendly_id? method any more with version 5

Actually please ignore that part of my comment! I got confused between branches - that method is in fact still there.

redbush commented 11 years ago

Hi norman,

Thank you for the reply. Would I have to set the slug to nil to avoid the UUID in the url or is this unavoidable? Thank you.