[英]How do I include rails items in a JSON string object?
我正在尝试将此字符串发送到我的Stripe帐户以处理交易,并且我想同时将要购买的商品的ID和所支付的金额作为JSON字符串发送。 如何在字符串中包含模型的各个部分?
customer = Stripe::Customer.create(email: email, description: {"amount:" amount, "id:" idea_id}')
模型的一部分是金额,另一部分是idea_id
假设您的模型称为产品
@product = Product.find(params[:id])
customer = Stripe::Customer.create(email: email, description: {amount: @product.amount, id: @product.idea_id}.to_json)
或者你也可以使用
customer = Stripe::Customer.create(email: email, description: @product.as_json(only: [:amount, :idea_id]))
但是,如果您绝对要求idea_id的键为“ id”,则此方法可能无效。 在这种情况下,请使用第一个选项。
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.