Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Friendly Id Custom Slug

I have a Post model

#post.rb   
extend FriendlyId
friendly_id :slug_candidates, use: [:slugged, :history]

I'm trying to customize the url for each post like so

#post.rb 
def slug_candidates
 "#tutorial-#{user.display_name}-#{title}"
end

Friendly id keeps generating UUID slugs while I'd like it to generate a comprehensive url

Typically I get \tutorial-john-49c9938b-ece5-4175-a4a4-0bb2b0f26a27 Instead of \tutorial-john-some-comprehensive-title

Thank you

like image 743
Zonblar Avatar asked Apr 06 '16 16:04

Zonblar


1 Answers

I edited the response, sorry. It seems friendly_id expects an array of slug candidates. As you can see here

please try this:

#post.rb 
def slug_candidates
  [ "#tutorial-#{user.display_name}-#{title}" ]
end
like image 119
amalrik maia Avatar answered Oct 27 '22 01:10

amalrik maia