I am running a Rails 5 application which has 2 models - a User
and a Provider
. I am using multiple table inheritance to show that each Provider
"is a" User
(via the active_record-acts_as
gem). So, in effect, creating a Provider
with the related fields would create a User
at the same time.
I wanted to implement slugging for these models, so I integrated the friendly_id
gem for that purpose.
Both models are slugged via a field called username
. The code in question being:
class User
extend FriendlyId
friendly_id :username, use: :slugged
# ...
end
for the User
model and
class Provider
extend FriendlyId
friendly_id username, use: :slugged
def username
acting_as.username # this fetches the parent model (User)'s username field.
end
# ...
end
for the Provider
model.
When I attempt to create a Provider
via a controller action (providers#create
), it fails, with the error being:
TypeError at /providers
nil is not a symbol nor a string
The stack trace identifies the problem to be at lib/friendly_id/slugged.rb:299
, which is the body of the should_generate_new_friendly_id?
method. This method was called by the set_slug
method in the same file, slugged.rb
.
I have created an issue on the GitHub page of friendly_id, where you can find the request parameters and full stack trace.
Edit: added friendly_id_config
for both: https://gist.github.com/mindseyeblind/9b78c588f5008a494f7157e72da1de6e