I'm interested in generating slug with both title and id. Otherwise, I would get errors like post collection route overriding single post route.
class Post > ApplicationRecord
extend FriendlyId
friendly_id [:id, :title], use: :slugged
end
resources :posts do
get "videos", on: :collection
end
Slug "videos" would conflict with "videos" collection route.
Is it possible to generate an slug with id and title?
"#{id}_#{title}" # Friendly Id slug
Friendly Id can not do that because it generates slug before save so it will not have id https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L250
You may need to use
to_parammethod to custom this:But then you need to write custom method to find a record id, something like in your controller: