When I add a new "product" using my scaffold create rails app, the following line properly adds a new product
@product = Product.new(params[:product])
When I try to add a new product using the following URL (trying to POST data up from a java program).
http://localhost:3000/products?serial=555&value=111
The product is not created, however I can access the "serial" and "value" values like this:
@product = Product.new
@product.serial=params[:serial]
@product.value=params[:value]
@product.save
To further confuse me, if I use the rails app to add a new product, the params[:serial]
and params[:value]
variables are empty.
Can someone please point me in the right direction.
Thanks
The Model.new method takes a hash.
params[:product]
actually contains something like {:serial => 555, :value => 111}
The url you would want to use is:
http://localhost:3000/products?product[serial]=555&product[value]=111
(Make sure that you are indeed using POST)
If you want to keep your current url scheme you would have to use:
@product = Product.new({:serial => params[:serial], :value => params[:value]})
You can also determine exactly what is available inside of params by printing it out to console using:
p params
Good luck!
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