0

I have the following model

class Business < ApplicationRecord {
               :id => :integer,
    :business_name => :string,
         :place_id => :string,
          :surburb => :string,
             :type => :text,
       :created_at => :datetime,
       :updated_at => :datetime
}

I am sending a JSON object to my api create method this is my object

business_params = {
    :business_name => "Endah Parade",
          :surburb => "Taman Sri Endah",
             :type => [
        [0] "premise",
        [1] "point_of_interest",
        [2] "establishment"
    ],
         :place_id => "ChIJixfh-49KzDERePyk34svbaY"
}

In my controller i run the following

business = Business.create!(business_params)

but i get the error TypeError (no implicit conversion of Array into String). My type column was defined as this

change_column :businesses, :type, :text, array: true, default: [], using: "(string_to_array(type, ','))"

So at least i know that my type column can accept array but i am not sure why i get this error.

In my Business Model, i added the following as well serialize :type, Array but it also doesnt help. I get the same error.

How can i solve this issue?

I am using Rails 5.1

1 Answer 1

2

That's because Rails uses type column by default for STI implementation.

Disabling of STI should help:

class Business
  self.inheritance_column = nil
end
Sign up to request clarification or add additional context in comments.

3 Comments

nice one @igor. got it. i just changed my column name instead
You should accept the solution as it answers your question, just to reward him, a SO way to say thanks. :)
@KingsleySimon if you think the question is answered, then accept it to mark it as completed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.