Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含获取名称和标题值的文本框的表单。并且存在一个提交按钮。我想获取文本框的值并将其以如下所示的格式发送到 api。
{ "entry": { "name":"api-workspace", "title":"API Workspace" } }
我怎么能用红宝石做到这一点?如果可用,请给我一些示例代码。
这些值在params散列中传递给您的控制器。假设您的文本字段的名称是name并且title这应该有效:
params
name
title
json = { entry: { name: params[:name], title: params[:title] } }.to_json puts json # => {"entry":{"name":"api-workspace","title":"API Workspace"}}