将查询字符串参数作为表单发布的一部分发送 [英] Send querystring params as part of form post

查看:44
本文介绍了将查询字符串参数作为表单发布的一部分发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法捕获查询字符串并将其作为表单帖子的一部分发送?我正在使用 Rails 2.3.5 并且我的用户位于具有多个查询字符串参数的页面上.在此页面上,他们将提交一个表单.在接收帖子的操作中,我想知道那些查询字符串参数是什么.显然,它们不是作为邮件的一部分发送的.所以我需要实际的表单值,以及用户提交表单时页面上的查询字符串参数.

Is there a way to capture the querystring and send that along as part of a form post? I'm using Rails 2.3.5 and my user is on a page that has multiple querystring parameters. On this page, they are going to submit a form. Inside the action that receives the post, I want to know what those querystring parameters were. Obviously, they are not sent as part of the post. So I need the actual form values, plus the querystring params that were on the page when the user submitted the form.

我确信我可以编写一些讨厌的 javascript 将查询字符串参数推送到表单上的隐藏字段中,以便它们可用,但这看起来很丑陋.我的谷歌搜索并没有出现太多,这让我怀疑我是否只是在做这一切都错了.更糟糕的是,我是一个 Rails 新手.

I'm sure I could write some nasty javascript that would shove the querystring params into hidden fields on the form so they would be available, but that seems ugly. My Googling hasn't turned up much, which makes me wonder if I'm just going about this all wrong. To make matters worse, I'm a Rails newbie.

感谢任何让我朝着正确方向前进的指示或想法.

Appreciate any pointers or ideas to get me going in the right direction.

推荐答案

我的一个朋友向我展示了我认为更简单的方法:

A friend of mine showed me what I believe is an easier way:

<% form_tag params.merge(:action=>"someAction") do %>

将参数合并到制作 form_tag 所需的散列中就完美了.

Merging params into the hash necessary for making the form_tag did the trick perfectly.

这篇关于将查询字符串参数作为表单发布的一部分发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆