I've used the FriendlyId gem (version 4.0.8) with a Rails application. I've followed the tutorial on RailsCasts and based on the documentation, I have to run Model.find_each(&:save)
on rails console to generate slugs for old records. However, when I do this, all of my old records still have nil for their slug attributes, so it doesn't really change the url's.
Am I doing something wrong? This only happens on production by the way. It works fine on development.
Update:
My model looks like this:
class Member < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
belongs_to :gym
attr_accessible :category, :name, :description
validates :category, :name, :description, :presence => true
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
def self.search(search)
if search.present?
where("name LIKE ?", "%#{search}%")
else
find(:all)
end
end
def should_generate_new_friendly_id?
new_record?
end
end
model
look like? – starscream_disco_partyshould_generate_new_friendly_id?
block? – Nils Landt