Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionController::ParameterMissing (param not found: order) [duplicate]

I am trying to send a post request using the Postman chrome extension to my Ruby on Rails app, but i keep getting the error

ActionController::ParameterMissing (param not found: order):
app/controllers/orders_controller.rb:27:in order_params'
app/controllers/orders_controller.rb:20:in create

The code in my orders_controller is

class OrdersController < ApplicationController
  protect_from_forgery :except => :create

  def new
    @order = Order.new
  end

  def index
    @orders = Order.all  
  end

  def show
    @order = Order.find(params[:id])    
  end

  def create
    @order = Order.new(order_params)
    render text: params[:product]   
  end

  private

  def order_params
    params.require(:order).permit(:product)
  end
end

My key Value pairs to the Postman extension are product[product_name] Samsung

like image 759
Ben Avatar asked Dec 03 '13 08:12

Ben


2 Answers

For you to use params.require(:order). the incoming parameters should be something like {"order"=>...}

Check the documentation at http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html to use Strong Parameters,.

Based on your information about the key-value pairs used, there is no key called "order" in the incoming-data. That's the reason - its failing.

Hope, this helps

like image 127
Satya Kalluri Avatar answered Oct 19 '22 05:10

Satya Kalluri


Probably the params method is requiring something that you don't have. Inspect the params.

This worked for me:

Controller:

def progress_params
    params.require(:progress).permit(:game_id, :level_id)
end

View:

<%= link_to "Completed", progresses_path(:progress =>{:game_id => @level.game_id.to_i, :level_id => @level.id.to_i} ), :method => :post %>
like image 44
rovitulli Avatar answered Oct 19 '22 06:10

rovitulli