Rails - 传递:url 中的参数
我又被困住了一次……我又一次怀疑这是一个愚蠢的语法问题:
我想用我的超级简单的搜索表单在 url 中传递 2 个变量。
我期待这样的网址: http://mydomain/categories/search?search=pdf&os=2 但我明白了: http://mydomain/categories/search?search=pdf&os[]=< /a>
我认为它应该像这样工作:
<% 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 %>
...但是,它没有这样做...
有谁知道我哪里出错了?
谢谢!
瓦尔
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.
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[]=
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
hidden_field_tag
稍微修改该行:请参阅 hidden_field_tag 文档了解更多信息。
You need to modify the line a bit, using
hidden_field_tag
:See the hidden_field_tag documentation for more information.
要用@category.id访问params hash中的一个key,有这样的key吗?看起来不是,因为它返回零。
似乎你想要一些效果
Is going to access a key in the params hash with @category.id, is there such a key? Looks like not, as its returning nil.
Seems like you want something to the effect of