0
我有以下型號類型錯誤(陣列中的隱式轉換成字符串)上創建方法的活動記錄軌道
class Business < ApplicationRecord {
:id => :integer,
:business_name => :string,
:place_id => :string,
:surburb => :string,
:type => :text,
:created_at => :datetime,
:updated_at => :datetime
}
我送一個JSON對象,以我的API創建方法,這是我的對象
business_params = {
:business_name => "Endah Parade",
:surburb => "Taman Sri Endah",
:type => [
[0] "premise",
[1] "point_of_interest",
[2] "establishment"
],
:place_id => "ChIJixfh-49KzDERePyk34svbaY"
}
在我控制我運行下面的
業務= 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
好的一個@igor。得到它了。我只是改了我的專欄名稱 –
你應該接受解決方案,因爲它回答你的問題,只是爲了獎勵他,一種SO的方式來表示感謝。 :) –