简体   繁体   中英

How to fix activeuuid gem error while upgrading from Rails4 to Rails5

I am updating my application from rails 4 to rails 5. My application is using activeuuid gem. The activeuuid gem is using alias_method_chain internally and this method is deprecated in rails 5. Now when I am trying to start rails console, I am getting error -

undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::Column:Class (NoMethodError)

Is there anyway I can continue using activeuuid gem in rails 5 and does not need to do any rework?

Rails 5 has built-in support for UUID primary keys, so ideally you should migrate away from this gem...

Try just delete this gem from your project and all must be fine.

Source: https://github.com/jashmenn/activeuuid/issues/80

However if you want to keep using this gem you can find (or create your own) fork. Last commit to original gem was 4 years ago (before rails 5 release). But I see forks where support for rails 5 was realized.

Since I didn't received any solution to this problem and after searching all around I came to below solution -

  1. Removed the activeuuid gem from the application.
  2. Implemented uuids with Ruby's SecureRandom class - Rails 5 Mysql UUID
  3. In case if someone finds issue in saving record as activeuuid limits database column to 16 Bytes, one can use SecureRandom.hex(8).encode("UTF-8")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM