Rails 请问如何禁止以 query string 的形式访问接口

birbird · December 05, 2014 · Last by birbird replied at December 05, 2014 · 1690 hits

有一个接口,比如 /notices/:id,其实写成 /notices?id=1,也是能正确访问的

有没有办法,强制必须写成 /notices/:id,不允许以 /notices?id=1 这种形式访问?

谢了先!

使用 post 方法?

#1 楼 @ywjno 谢谢提醒,不过我这是个查询,GET 合适一些,最好还是不要 POST

这个是路由控制的啊

默认情况下

ruby-china.org/topics/23048 定位到 topics#show ruby-china.org/topics?id=23048 定位到 topics#index

关键看你路由和控制器里怎么写的

#3 楼 @libuchao 多谢提示,我刚才糊涂了,这就不应该是个问题。

You need to Sign in before reply, if you don't have an account, please Sign up first.