This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts a phone number with letters to a phone number with only numbers. | |
# Leaves any other characters untouched. | |
class VanityPhoneNumberConverter | |
LETTER_TO_NUMBER = { | |
'a' => '2', 'b' => '2', 'c' => '2', | |
'd' => '3', 'e' => '3', 'f' => '3', | |
'g' => '4', 'h' => '4', 'i' => '4', | |
'j' => '5', 'k' => '5', 'l' => '5', | |
'm' => '6', 'n' => '6', 'o' => '6', | |
'p' => '7', 'q' => '7', 'r' => '7', 's' => '7', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
models = ActiveRecord::Base.descendants | |
models.each do |m| | |
last_id = m.last.id | |
m.connection.execute("ALTER SEQUENCE #{m.table_name}_id_seq RESTART WITH #{last_id}")"; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails datetime_select and similar use multiparameter attributes which are | |
# these dawful things from the bowels of activerecord and actionpack. This | |
# module extends virtus models to coerce multiparameter attributes back together | |
# before assigning attributes. | |
# | |
# Here's the implementation for ActiveRecord: | |
# | |
# https://github.com/rails/rails/blob/11fd052aa815ae0255ea5b2463e88138fb3fec61/activerecord/lib/active_record/attribute_assignment.rb#L113-L218 | |
# | |
# and DataMapper: |
OlderNewer