I'm quite new to RoR and I got a question regarding initialization of libraries. how do I load up a class I extended from an existing class library in rails?
I'd like to extend the ActiveRecord::base as below based on this link
# lib/active_record/add_reset_pk_sequence_to_base.rb
module ActiveRecord
class Base
def self.reset_pk_sequence
case ActiveRecord::Base.connection.adapter_name
when 'SQLite'
new_max = maximum(primary_key) || 0
update_seq_sql = "update sqlite_sequence set seq = #{new_max} where name = '#{table_name}';"
ActiveRecord::Base.connection.execute(update_seq_sql)
when 'PostgreSQL'
ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
else
raise "Task not implemented for this DB adapter"
end
end
end
end
On purpose, I would like to use the extended class in seed.rb to reset auto increment of tables. how do I load the file with the 'require' statement? I have tried several ways, unfortunately, things didn't work out fine for me?
any advice would be very much appreciated?