gpt4 book ai didi

ruby-on-rails - Rails 通过 GET 创建数据库条目?

转载 作者:可可西里 更新时间:2023-11-01 16:24:33 26 4
gpt4 key购买 nike

是否可以通过 GET 请求而不是 POST 来创建数据库条目(创建方法)?

提前致谢。

最佳答案

现在我有了更多的细节,这里是一些答案。如果您收到此类请求:

your_route?price=123&name=abc

制作如下路线:

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

如果您有可选参数,请使用括号。

在您的 Controller 中,您将获得参数。假设您有一个包含 pricename 列的 Product 模型,请按照以下步骤保存它:

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

关于ruby-on-rails - Rails 通过 GET 创建数据库条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4879547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com