Changing Friendly ID Default Column

1k views Asked by At

I'm trying to work out how to change the default column that Friendly Id generates the unique name to.

Currently, it requires the table to have a column called slug, but I need to generate a unique email address for an organisation, and 'slug' is not a correct identifier.

This is the code so far:

require 'friendly_id'

class Organisation < ActiveRecord::Base
    extend FriendlyId

    friendly_id :name, :use => :email
end

which generates

NameError: uninitialized constant FriendlyId::Email

I think there is the ability to do a config and set the defaults through that, but that would change the slug column everywhere. I just need to change it for a specific model.

1

There are 1 answers

2
Rajdeep Singh On BEST ANSWER

Try this out

friendly_id :name, use: :slugged, slug_column: :email