Friendly ID - undefined method `slug=' for
friendly-id, paper-trail-gem, ruby-on-rails
Solution
Now, I have introduced Friendly ID without slug column
I don't know exactly what you mean here, but simply, it's like trying to start a car without the key
FriendlyID
The way FriendlyID works is to use a `slug` (or other identifier) column to both create the slugged URL, and find based off the slugged ID:
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
This allows the gem to find based off either the `id` or the `slug` attribute
If you miss out the `slug` column, this will prevent this from working, causing your error. The ways to fix this are:
- Use the slug column
- Create a slug attribute using `attr_accessor`
If you'd like to try the second option, you could try this:
#app/models/ModelName.rb
attr_accessor :slug
Problem
I am using the gems Workflow, Paper Trail and Friend ID. To track the state changes using Paper Trail, I have overridden the persist_workflow_state to explicitly update the workflow column, so that Paper Trail can capture the change. https://github.com/geekq/workflow#integration-with-activerecord ``` def persist_workflow_state(new_value) update_attribute self.class.workflow_column, new_value end ``` Now, I have introduced Friendly ID without slug column, and I get the error, upon reaching the above method. ``` undefined method `slug=' for #<ModelName:0x007f81cf342cd8> ``` Any help?