I am unable to create to insert an array into the database. All of the other fields are entered correctly. I get the following messages: Completed 406 Not Acceptable in 30ms (ActiveRecord: 21.8ms)
and ActionController::UnknownFormat (ActionController::UnknownFormat
Here is the object that comes in as it leaves my front end:
{ dealer_name: 'Dealer Name',
customer_first_name: 'John',
customer_last_name: 'Doe',
customer_phone_number: '555-555-5555',
customer_email: 'john.doe@domain.com',
notes: 'some notes about this transaction',
attachmentUrls: [
'https://path-to-s3/file-name1.jpg',
'https://path-to-s3/file-name2.jpg',
'https://path-to-s3/file-name3.jpg'
]
}
Here's it coming into the Rails backend per logs:
Parameters: {"dealer_name"=>"Dealer Name", "customer_first_name"=>"John", "customer_last_name"=>"Doe", "customer_phone_number"=>"555-555-5555", "customer_email"=>"john.doe@domain.com", "notes"=>"some notes about this transaction", "attachmentUrls"=>['https://path-to-s3/file-name1.jpg','https://path-to-s3/file-name2.jpg', 'https://path-to-s3/file-name3.jpg']}
Here's more logs:
SQL (1.0ms) INSERT INTO "military_discounts" ("dealer_name", "customer_first_name", "customer_last_name", "customer_phone_number", "customer_email", "notes", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["dealer_name", "Dealer Name"], ["customer_first_name", "John"], ["customer_last_name", "Doe"], ["customer_phone_number", "555-555-5555"], ["customer_email", "john.doe@domain.com"], ["notes", "notes about this transaction"], ["created_at", 2017-04-05 17:58:56 UTC], ["updated_at", 2017-04-05 17:58:56 UTC]]
Here's my API controller:
class Api::MilitaryDiscountsController < ApplicationController
# before_action :set_military_discount, only: [:show, :edit, :update, :destroy]
# POST /military_discounts
# POST /military_discounts.json
def create
@military_discount = MilitaryDiscount.new(military_discount_params)
respond_to do |format|
if @military_discount.save
format.json { render json: @military_discount.to_json, status: :created }
}
else
format.json { render json: @military_discount.errors, status: :unprocessable_entity }
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def military_discount_params
params.require(:military_discount).permit(:dealer_name, :customer_first_name, :customer_last_name, :customer_phone_number, :customer_email, :notes, :attachmentUrls)
end
end
Rails migration file, and the DB is postgresql:
class CreateMilitaryDiscounts < ActiveRecord::Migration[5.0]
def change
create_table :military_discounts do |t|
t.string :dealer_name
t.string :customer_first_name
t.string :customer_last_name
t.string :customer_phone_number
t.string :customer_email
t.text :notes
t.text :attachmentUrls, array: true, default: []
t.timestamps
end
end
end
What am I missing? How do I get the attachmentUrls
array to get inserted into the database?