1b86216f2be83ba32b1e910c66d9a856

Looking for a less cumbersome way to add an record id to either the front or back of a friendly_url depending upon a flag value.

friendly_url = @object.id.to_s
name = unimportant_dasherize_method(@object.name)

unless name.blank?
  if trailing_id_binary_flag
    friendly_url = name << "-#{friendly_url}"
  else
    friendly_url << "-#{name}"
  end
end

Refactorings

No refactoring yet !

B8ba61cc84ecb63c859435be28547dfb

steved

December 18, 2010, December 18, 2010 00:07, permalink

2 ratings. Login to rate!
name = unimportant_dasherize_method(@object.name)  # fix this to return nil rather than blank

array = [@object.id.to_s, name].compact
array.reverse! if trailing_id_binary_flag
friendly_url = array.join('-')

Your refactoring





Format Copy from initial code

or Cancel