简体   繁体   English

Rails从渲染的表单中删除参数

[英]Rails remove params from rendered form

i have a form in a page, with submit button. 我在页面中有一个表单,带有“提交”按钮。 Form contains some inputs. 表单包含一些输入。 When user press sumbit button, he gets so link: 当用户按下sumbit按钮时,他将获得以下链接:

/top?user_id=67508&country=&state=&city=&mode=0&page=19

How to remove empty params, user should not see it - country, city, state in this example 如何删除空参数,用户不应看到它-在此示例中,国家,城市,州

params.delete :country - don't works params.delete:country-不起作用

You cannot stop any parameters from being submitted from the client by using ruby code. 您无法使用ruby代码阻止任何参数从客户端提交。 This could easily be solved through Javascript by listening to the submit event of the form, and attaching a handler to this event which filters the parameters. 这可以通过Javascript轻松解决,方法是侦听表单的submit事件,并将处理程序附加到此事件以过滤参数。

See this answer for an example. 有关示例,请参见此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM