gpt4 book ai didi

ruby-on-rails - 当我在 rails 中以 json 形式发送时,路径参数不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:26 24 4
gpt4 key购买 nike

在 route 我有这样的东西

  match '/*parent/:term/' => "parent#match" ,

例如,当我在服务器中点击这个 url 时,它是这样的

localhost:3000/women/jeans

当我点击 html 请求时的日志

Parameters: {"parent"=> "women", "term"=>"jeans"}

当我点击 json 请求时的日志(localhost:3000/women/jeans.json)

Parameters: {"parent"=>{}, "term"=>"jeans"}

我不知道为什么当我发送为 json 时父参数为 null

最佳答案

在您的 match 之前,您是否有任何其他可能与您的 URL 匹配的路由?

我刚刚试过了,一切看起来都很好:

# routes.rb
match '/*parent/:term/' => 'parent#match', via: :get

# Generates:
GET /*parent/:term(.:format) parent#match

# http://localhost:3000/women/jeans
{"parent"=>"women", "term"=>"jeans"}

# http://localhost:3000/women/jeans.json
{"parent"=>"women", "term"=>"jeans", "format"=>"json"}

看起来问题出在其他地方。

关于ruby-on-rails - 当我在 rails 中以 json 形式发送时,路径参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045362/

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