隐藏请求参数和简单的 GET 请求
有一个文章和标签模型。
要查找与特定标签关联的文章,用户单击链接并转到“/articles?tags=iPhone”URL。
除了“tags”参数之外,我还需要向服务器传递另一个参数,例如“hiddenParam”,不应出现在地址栏中。
因此,用户应该在地址栏中看到“/articles?tags=iPhone”,并且还应该在请求正文中提供额外的“hiddenParam”。
在 Rails 中使用标准 ActionView 助手,这是否可能?
there is an Article and Tag model.
To look for articles, associated with specific Tag, user clicks a link and follows to "/articles?tags=iPhone" URL.
In addition to "tags" param, i need to pass another param to server, say "hiddenParam", which should not be appeared in address bar.
So, the user should see "/articles?tags=iPhone" in address bar and additional "hiddenParam" should also be provided in request body.
Is this even possible, using standard ActionView helpers in Rails ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该发送一个 POST 请求,其中包含您不希望在 URL 栏中可见的变量,但设置请求路径以包含您确实希望可见的参数。
一个示例卷曲请求是:
然后在您的控制器中,两个参数都应该可用。
但是,请记住,该页面在当前状态下将无法添加书签/链接。如果您确实需要除当前用户之外的任何人都可以使用该 url,那么您可能确实想要加密或散列隐藏参数并通过 get 传递它。
附言。为什么没有 /tags/:id 路线?
You should send a POST request with the variables that you don't want to be viewable in the URL bar, but set the request path to include the parameter you do want to be viewable.
An example curl request would be:
Then in your controller, both parameters should be available.
However, bear in mind that the page will not then be bookmarkable/linkable in its current state. You may really want to encrypt or hash the hidden parameter and pass it in via get if you do need the url to be available to anyone but the current user.
PS. Why don't you have a route that is /tags/:id ?
如果您确实必须这样做,请尝试以下操作:
然后使用 CSS 样式使您的按钮显示/看起来像链接。
但请记住,这不适用于搜索引擎。
If you really must, try this:
Then use CSS styling to make your button appear/look like a link.
Keep in mind though, that this won't work well with search engines.