我有以下型号
class Business < ApplicationRecord {
:id => :integer,
:business_name => :string,
:place_id => :string,
:surburb => :string,
:type => :text,
:created_at => :datetime,
:updated_at => :datetime
}
我正在向我的api create方法发送一个JSON对象,这是我的对象
business_params = {
:business_name => "Endah Parade",
:surburb => "Taman Sri Endah",
:type => [
[0] "premise",
[1] "point_of_interest",
[2] "establishment"
],
:place_id => "ChIJixfh-49KzDERePyk34svbaY"
}
在我的控制器中,我运行以下
business = Business.create!(business_params)
但我收到错误TypeError (no implicit conversion of Array into String)
。我的type
列定义为此
change_column :businesses, :type, :text, array: true, default: [], using: "(string_to_array(type, ','))"
所以至少我知道我的类型列可以接受数组,但我不知道为什么我会收到此错误。
在我的商业模式中,我添加了以下serialize :type, Array
,但它也没有帮助。我犯了同样的错误。
我该如何解决这个问题?
我正在使用Rails 5.1
答案 0 :(得分:1)
这是因为Rails
默认使用type
列来实现STI
。
禁用STI
应该会有所帮助:
class Business
self.inheritance_column = nil
end