简体   繁体   English

Rails-将多个参数传递给form_tag

[英]Rails - passing multiple params to a form_tag

I have a form_tag that I'm using for a search. 我有一个用于搜索的form_tag。 I need to pass not only the :term (what is being searched for), but also the :ques_num parameter. 我不仅需要传递:term(正在搜索的内容),还需要传递:ques_num参数。 Currently, :ques_num is not being passed in. 当前,:ques_num没有被传入。

<%= form_tag display_questions_path(:ques_num => 2), method: :get do %>
  <%= text_field_tag :term, params[:term], placeholder: "Search Terms..." %>
<% end %>

This directs me to the address with the :term passed in, but not :ques_num. 这会将我定向到带有:term传入的地址,而不是:ques_num。 How would I go about doing this? 我将如何去做呢?

You should use hidden_field_tag instead: 您应该改用hidden_​​field_tag

<%= form_tag display_questions_path, method: :get do %>
  <%= text_field_tag :term, params[:term], placeholder: "Search Terms..." %>
  <%= hidden_field_tag :ques_num, 2 %>
<% end %>

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

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