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:
(Make sure that you are indeed using POST)
If you want to keep your current url scheme you would have to use:
You can also determine exactly what is available inside of params by printing it out to console using:
Good luck!