Access POST Options

When I add a new “product” using my rails creation application, the next line correctly adds the new product

@product = Product.new(params[:product])

When I try to add a new product using the following URL (trying to get POST data from a java program).

http://localhost:3000/products?serial=555&value=111

The product was not created, however I can access the values ​​of "serial" and "value" as follows:

 @product = Product.new
 @product.serial=params[:serial]
 @product.value=params[:value]
 @product.save

To further confuse me if I'm using rails application to add a new product, the variables params[:serial]and params[:value]empty.

Can someone please call me in the right direction.

thanks

+5
source share
1 answer

The Model.new method accepts a hash.

params[:product] really contains something like {:serial => 555, :value => 111}

URL-, :

http://localhost:3000/products?product[serial]=555&product[value]=111

(, POST)

URL-, :

@product = Product.new({:serial => params[:serial], :value => params[:value]})

, , , :

p params

!

+9

All Articles