How to fix duplicate model name with gem

I am trying to use a gem which is ging / mailboxer in my rails application. In the pearl, the "Receipt" class is used in the model. But I already use the "Receipt" class in my application.

In this case, the model name and table name are duplicated. so what's the best way to fix the duplicate model name?

I think below:

  • Way1: renaming model name / table in gem
  • Way2: rename model / table name in my application

I did not find any combination to accept Way1.

If I settle Way2, I will rename the table name and then rename the model name in my application. If possible, I would like to avoid this because I have already used the "Receipt" in many places.

Should I accept Way2, or is there another good way to fix the duplicate model name?

+4
source share
1 answer

As you said, since they are ActiveRecord classes, they have the same table, and they will collide in the namespace of your application.

You can use Modules to avoid a collision with a class of names, or you can update either a gem or your code to use a different name for the class.

If you decide to put your classes in a module, for a raw database table, you can use set_table_name to use a different name for this class instead of the default one expected by ActiveRecord.

0
source

All Articles