I have two models in my app that make use of the Friendly_id gem (it so that the app's URLs are more descriptive and user-friendly.
A Politician Model:
class Politician < ActiveRecord::Base
has_many :interests
has_many :issues, through: :interests
validates :name, :political_party, :title, :slug, presence: true
extend FriendlyId
friendly_id :name, use: :slugged
end
and an Issue Model:
class Issue < ActiveRecord::Base
has_many :interests
has_many :politicians, through: :interests
validates :name, :slug, :keywords, presence: true
extend FriendlyId
friendly_id :name, use: :slugged
end
Back story: The app wasn't initially pushed to Heroku with the gem installed. I built the app and deployed it to Heroku, and then I came across the Friendly_ID gem. After discovering it, I installed the gem in my Gemfile, tweaked the aforementioned models and controllers, and it works beautifully on my local server.
I thought I was all set. I re-seeded my data on Heroku, and pushed it up, but the changes won't show on the live site. And so instead of using the slug field for each model like so:
www.mysite.com/politicians/barack-obama
www.mysite.com/issues/economy
I still see:
www.mysite.com/politicians/7 (Barack Obama's politician ID number)
www.mysite.com/issues/3 (the ID number for the "Economy" issue)
More Back Story:
I looked at the gem's docs and even a few questions here on StackOverflow, and they all said that if you're adding the gem to a pre-existing app, then to run this code in the Heroku console for each model that the friendly_id gem is applied to:
heroku run console
And then:
Politician.find_each(&:save)
Issue.find_each(&:save)
That didn't work :-/ My app is still not updated with semantic-friendly URLs. I should also add that I initially made use of the gem's helper module. And so, I had:
friendly_id :name, use: [:slugged, :history]
But someone on this StackOverflow thread mentioned to remove the "helper" keyword (and then re-add it after saving?), since that may be preventing it from updating on Heroku. I haven't tried that yet (re-adding the "helper" keyword after saving, but I wanted to put up my question before I wasted another day of trying something, and it not working.
Help please :-)