I am having trouble with a search form and restful routes.
In my app I have a Topic model and a Classroom model. Topics can exist in classrooms but don't have to so for that reason I have not nested them.
I want to have a form that passes a topic_id and the search parameter. So I have a form that looks like this:
<% form_tag ({:action => "show", :topic_id => @topic.id, :id => @classroom.id} , {:method => 'get'}) do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %>
But when I submit the form the search param is posted but the topic_id param is stripped. So when searching for 'gen' I get:
/classrooms/1?search=gen
instead of:
classrooms/1?search=gen&topic_id=43
The strange thing is that if I embed this in a link_to (setting the additional param :search to a fixed value) the topic_id param doesn't get stripped. It is only when it is submitted via the form that the topic_id parameter is stripped.
Any ideas?
Thanks