2

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

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That's great! Thank you Veger! I end up retrieving the id via params[:symbol]: <%= hidden_field_tag :os, params[:id] %> Works great!
2
  <%= 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 %>

1 Comment

Hi micholson! Thanks for the quick reply! I tried that and it returns mydomain/categories/search?search=pdf&os[2]= (with 2 being the correct category.id) But that doesn't give me access to the value like ... mydomain/categories/search?search=pdf&os=2 ..., does it? Val

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.