[英]rails - passing :params in url
I am stuck one more time ... and one more time I suspect it's a stupid syntax problem: 我再次陷入困境......还有一次我怀疑这是一个愚蠢的语法问题:
I want to pass 2 vaiables in the url with my super simple search form. 我想用我的超级简单搜索表单在网址中传递2个vaiables。
I was expecting a URL like this: http://mydomain/categories/search?search=pdf&os=2 But I get this: http://mydomain/categories/search?search=pdf&os[]= 我期待这样的URL: http:// mydomain / categories / search?search = pdf&os = 2但是我得到了这个: http:// mydomain / categories / search?search = pdf&os [] =
I thought it should work like this: 我认为它应该像这样工作:
<% form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= hidden_field :os, params[@category.id] %>
<%= submit_tag "Search", :name => nil %>
<% end %>
... but well, it didn't do it ... ......但是,它没有做到......
Does anyone know where I am going wrong? 有谁知道我哪里出错了?
Thanks! 谢谢!
Val 瓦尔
You need to modify the line a bit, using hidden_field_tag
: 你需要使用
hidden_field_tag
修改一下这一行:
<%= hidden_field_tag :os, :value => @category.id %>
See the hidden_field_tag documentation for more information. 有关更多信息,请参阅hidden_field_tag文档 。
<%= hidden_field :os, params[@category.id] %>
Is going to access a key in the params hash with @category.id, is there such a key? 是否会使用@ category.id访问params哈希中的密钥,是否有这样的密钥? Looks like not, as its returning nil.
看起来不像,因为它的回归为零。
Seems like you want something to the effect of 好像你想要的东西效果
<%= hidden_field :os, @category.id %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.