0

我在我的 ruby​​mine 控制台上完成了 rails c。

我想在 Rails 控制台中执行一个函数。

功能是

funtion_one(Api_payload , some_integer_Value)

API_payload 是:-

{
"data" : [
    {
        "from" : "today",
          "to" : "next_day"
    }
],
  "some_ids" : [
    9808
]
}

所以基本上我如何在rails控制台中编写它..?

pry(main)>  function_one({ "date_ranges" : [ { "from" : "today", "to" : "next_day" } ], "some_ids" : [ 9808 ] } , 25)

写完上面的命令后,出现错误,即SyntaxError: unexpected tIDENTIFIER, Expecting end-of-input

4

1 回答 1

1

您需要解析传入的有效负载,因为它不是 ruby​​ 哈希。

# Notice the ' and beginning and end, it needs to be a string

payload = '{
  "data" : [
      {
        "from" : "today",
        "to" : "next_day"
      }
    ],
   "some_ids" : [9808]
  }'

usable_payload = JSON.parse(payload)

# then call your method
method_one(usable_payload, 25)
于 2021-06-10T06:51:23.000 回答