Get uninitialized constant V1::Payment::V1Platform (NameError) when using has_and_belongs_to_many with Versioning #5505
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I create Payment model using command below:
rails g scaffold v1/Payment name type code
and added has_and_belongs_to_many, so the model looks like this:
class V1::Payment
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :type, type: String
field :code, type: String
has_and_belongs_to_many :v1_platforms
end
Then, i create Platform model using command below:
rails g scaffold v1/Platform name type code
and added has_and_belongs_to_many, so the model looks like this:
class V1::Platform
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :type, type: String
field :code, type: String
has_and_belongs_to_many :v1_payments
end
Then, i open rails console and try creating Payment using command below:
payment = V1::Payment.new(name: "Name", type: "Type", code: "Code")
payment.save
and get error like this,
/home/nizam/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/mongoid-8.0.2/lib/mongoid/association/relatable.rb:487:in block (2 levels) in resolve_name': uninitialized constant V1::Payment::V1Platform (NameError)
Did you mean? V1::Platform`
There is a mistyping in V1Platform, then i check the relatable.rb file and found that in relation_class definition,
This code below is changing the class_name string "v1_platform" into "V1Platform", instead V1::Platform.
cls_name = @options[:class_name] || ActiveSupport::Inflector.classify(name)
I don't know if it's a bug for classes with versioning or my mistake when creating a class.
*I already tried without using versioning, and it works. So maybe the V1:: prefix is the problem.
Beta Was this translation helpful? Give feedback.
All reactions