RailsCasts Pro episodes are now free!

Learn more or hide this

B. Besmer's Profile

GitHub User: besi

Comments by B. Besmer


Like the URL to this very page, I want to have urls like this:


So I use friendly_id like so:

extend FriendlyId

friendly_id :slug_candidates, use: :history

def slug_candidates
      [:id, :title]

Now, since friendly id generates the slug before the object is saved I end up with an url like so (Please note the missing id in the URL):


Now while this is not too bad as such. As soon as I save another Product called "Table Lamp", I will get an URL like this:


So my question is, how can I make sure, friendly ID creates the slug containing the ID as well.