-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
First record in a table has no slug #580
Comments
What steps can you provide us to reproduce this issue please? |
I have a plain setup as shown in the README extend FriendlyId
friendly_id :slug_candidates, :use => [:slugged]
def slug_candidates
[
:title,
[:title, :id]
]
end version is friendly_id (5.0.4) |
@bbnnt so you merely have to create a record like this: YourModel.create title: 'something' ...and you see the problem? |
Again, I'm not accurate enough, sorry. |
Would this solve your issues?: extend FriendlyId
friendly_id :slug_candidates, :use => [:slugged]
def slug_candidates
[
:title,
[:title, :id]
]
end
validates :title, :presence => true I would have thought that FriendlyId would expect a column that can't be blank to generate slugs from, would that make sense in your application? I've never used FriendlyId with a nullable field. |
I guess that would sure work, as the record wouldn't be saved then, not passing the validation. I maintain, with only one record in the table, the first one, created with the following : s = Song.create(:some_other_field_than_title => "xxxxx") The record get saved, slug is null. I go to the console, get back the record, update another field : s = Song.first
s.yet_another_field_but_not_title = "some value"
s.save slug still blank. Let's save a title : s = Song.first
s.title = "some value"
s.save slug still blank. It then works for all the further records. But if I even try to have the expected behavior on the very first record, it does not change (I save this discussion from the console tests on this las statement, but the slug does not get filled) For the very first record, the slug has to be filled manually |
What if you remove the |
Simplified to it : extend FriendlyId
friendly_id :title but still the same |
From what I see... I captured here the db records -> http://cl.ly/image/2N321a1d0r2P That's fine with a default unique hash ! What I'm saying is that Friendly_id do its job for the second one and all the others records coming after the second one, but will never do it for the first one |
@bbnnt can you try the experimental branch? gem 'friendly_id', :git => 'https://github.com/xymbol/friendly_id', :branch => 'fix-blank-slugs' |
I guess @xymbol 's branch fixes this ! -> http://cl.ly/image/1D0A0E1S2D3y |
👍 |
thx! |
It's all in the title, it won't bother that much as the first record is often a test record, but felt like something was missing somewhere.
Is there something in the setup that needs to be specified, or do we need to force a default to the slug field ?
As it is now, it seems that the slug does not generate if friendly_id does not have any other slugs to be compared to
The text was updated successfully, but these errors were encountered: