我正在使用gem Friendly ID,我目前必须进行2次保存以保存slu ..
对我来说似乎不对。
class Contractor < ActiveRecord::Base
include FriendlyId
friendly_id :slug_candidates, use: :slugged, slug_column: :alias
after_commit :generate_new_alias, unless: Proc.new {|contractor| contractor.business_name_changed? }
def slug_candidates
[
:business_name,
[:business_name, :city],
[:business_name, :city, :state]
]
end
def generate_new_alias
if self.alias != self.alias_was
self.alias = nil
self.save
end
end
end
知道我做错了吗?