jeudi 26 mai 2016

Failing to create a new record in rails

I'm attempting to create a new StockOrder by passing a JSON object from my front end to the server. The defined strong parameters for the StockOrders looks like this:

private
  def stock_order_params
    params.require(:stock_order).permit( [StockOrder.strong_params, :purchaser_id, :carriage_terms, :carriage_cost, :contact_id, :user_id, :currency, :default_vat_rate, :discount_cost, :dispatched_status, :due_date, :internal_notes, :invoice_address_id, :invoice_date, :payment_terms, :po_date, :vat_rate, :purchase_order_number, {stock_order_line_items_attributes: [StockOrderLineItem.strong_params, :_destroy, :id, :part_id, :description, :quantity, :unit_cost, :vat_rate, :quantity_to_dispatch, :sort_index] + StockOrderLineItem.additional_params}, :purchaser_notes, :delivery_address] + StockOrder.additional_params )
  end

In this you can see that I have two models: StockOrder & StockOrderLineItem.

Here is what I'm sending from my front-end:

{
 "stock_order":
    {
     "stock_order_line_items_attributes":
        {
         "part_id":2309,"unit_cost":15,
         "quantity_to_dispatch":5
        },
     "contact_id":10,
     "purchaser_id":10
    }
 }

And finally here is how I'm trying to create my new StockOrder:

@stock_order = StockOrder.new(stock_order_params)

But the server responds with this error:

Rails controller error

But I've looked at the models for both and, of the parameters that I'm passing, none of them are strings. Here's a snapshot of the schema for the tables:

# == Schema Information
#
# Table name: stock_orders
#
#  id                        :integer          not null, primary key
#  ref_no                    :integer
#  purchase_order_number     :string
#  contact_id                :integer
#  purchase_order_date       :date
#  carriage_terms            :text
#  payment_terms             :text
#  due_date                  :date
#  purchaser_id              :integer

And for the StockOrderItemList

# == Schema Information
#
# Table name: stock_order_line_items
#
#  id                     :integer          not null, primary key
#  stock_order_id         :integer
#  part_id                :integer
#  quantity               :decimal(, )
#  vat_rate               :float
#  unit_cost_cents        :integer
#  net_cost_cents         :integer
#  total_cost_cents       :integer
#  vat_cost_cents         :integer
#  local_unit_cost_cents  :integer
#  local_net_cost_cents   :integer
#  local_total_cost_cents :integer
#  local_vat_cost_cents   :integer
#  quantity_dispatched    :decimal(, )
#  created_at             :datetime         not null
#  updated_at             :datetime         not null
#  description            :text
#

Aucun commentaire:

Enregistrer un commentaire