Friendly_id generates slug with id

I'm trying to use the friendly_id pearl to create a bullet in the format "# {id} - # {title}"

Friendly_id seems to be using before_save and will not have access to the ID attribute.

Is there any work for this?

# Permalinks #----------------------------------------------------------------------------- extend FriendlyId friendly_id :id_and_title, :use => :slugged def id_and_title "#{id} #{title}" end 
+4
source share
1 answer

Instead of using friendly_id for this, you can override to_param in your model to include a header

 class YourModel < ActiveRecord::Base def to_param "#{id} #{title}".parameterize end end 

This should affect what you need without using friendly_id.

+13
source

Source: https://habr.com/ru/post/1395123/


All Articles