我可以x=y
用这样的隐藏字段的形式发送参数
<%= form_with(url: '/search', method: 'get') do %>
<%= text_field_tag(:query) %>
<%= hidden_field_tag(:x, 'y') %>
<%= submit_tag("Search") %>
<% end %>
是否可以在 URL 中发送参数?以下不起作用
<%= form_with(url: '/search?x=y', method: 'get') do %>
<%= text_field_tag(:query) %>
<%= submit_tag("Search") %>
<% end %>
正如您在此处阅读的那样,您在 HTML 表单action
属性中可能具有的查询字符串将不会被考虑在内。
翻译成你的form_for
问题,这意味着你的查询字符串url:
没有被考虑在内。
因此,您hidden_field_tag
是解决此问题的正确方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句