The class_name
must be pass as an string
, try this:
has_one :test_flow, class_name: "Flow"
質問
I struggling to get these relationships to work. I have the following class FlowContainer
class FlowContainer
include Mongoid::Document
has_one :production_flow, class_name: Flow
has_one :test_flow, class_name: Flow
has_one :design_flow, class_name: Flow
end
As you can see I want it to have 3 specific flows. And I setup the relationship in the Flow like this:
class Flow
include Mongoid::Document
belongs_to :flow_container
end
I don't think this is something special and should work in my opinion but when I try to assign a flow to one of the specific flows mentioned above I get this error message:
NoMethodError: undefined method `sub' for Flow:Class
I could also go for the inheritance setup for a generic flow and 3 sub class but for the moment I'm not in favor for that solution because I feel this should work. If somebody could share his opinion on this matter, I would appreciate it.
解決
The class_name
must be pass as an string
, try this:
has_one :test_flow, class_name: "Flow"