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
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
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 %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With