views:

370

answers:

2

Hi folks, 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

+1  A: 
  <%= 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 %>
rnicholson
val_to_many
+1  A: 

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.

Veger
That's great! Thank you Veger!I end up retrieving the id via params[:symbol]: <%= hidden_field_tag :os, params[:id] %>Works great!
val_to_many