rails - passing :params in url
-
21-09-2019 - |
문제
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
해결책
You need to modify the line a bit, using hidden_field_tag
:
<%= hidden_field_tag :os, :value => @category.id %>
See the hidden_field_tag documentation for more information.
다른 팁
<%= hidden_field :os, params[@category.id] %>
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
<%= hidden_field :os, @category.id %>
제휴하지 않습니다 StackOverflow