开发者

Rails create database entry by GET?

is it possible to c开发者_如何学Pythonreate a database entry (create method) by a GET request instead of POST?

thanks in advance.


Now I have some more details, here is some answer. If you'll receive this kind of request:

your_route?price=123&name=abc

Make a route like:

match 'your_route/:price/:name' => 'your_controller#your_method'

If ever you've optional params, use brackets.

in your controller, you'll get the params. Given you have a Product model with columns price and name, proceed as follows to save it:

@product = Product.new({:price => params[:price]), :name => params[:name]})
@product.save


What you do in response to a GET request is entirely up to you. Of course, multiple GET requests with the same parameters could potentially create multiple records, which might not be what you want. Browsers will resend GET requests but will normally prompt the user to resent POST requests.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜