jeudi 12 novembre 2015

Ruby on rails Common error: Params missing?

I am building a Order management system. I recently posted a problem about adding a order to a customer. It seems that i have fixed it for 99%. if i look in my terminal it first finds the current customer ID and then creates a new order. The following result is.

Customer Load (0.2ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = ? LIMIT 1 [["id", 111]] (0.1ms) begin transaction SQL (0.4ms) INSERT INTO "orders" ("customer_id", "created_at", "updated_at") VALUES (?, ?, ?) [["customer_id", 111], ["created_at", "2015-11-12 13:28:21.185604"], ["updated_at", "2015-11-12 13:28:21.185604"]] (8.2ms) commit transaction

But the problem is, it doesn't add the params. I did this intentionally just to check if my syntax would execute the following sql statement. But ones i add params i get a common error "param is missing or the value is empty: order"

Here is my code:

def createorders
    @customer = Customer.find(params[:id]) #find current id??
    #current_user = Order.find(params[:id])
    @orders = @customer.orders.new(order_params)


    if @orders.save
    flash[:notice] = "Subject created successfully"
    redirect_to(:action => 'index')
    else
    #If save fails, redisplay the form so user can fix problems
    render('new') #het zit in de new.html template
    end
  end




  private 

  def order_params
    #same as using "params[:subject]", expect that it:
    # - raises an error if :subject is not present
    # - allows listed attributes to be mass-assigned
  params.require(:order).permit(:pakket, :verstuurt)
      end
end

Thank you stackoverflow for showing me support. I am new with ruby, and i understand i am making noob mistakes. So pointing out flaws are welcome!

Aucun commentaire:

Enregistrer un commentaire