help with submitting a form by clicking on a link

Hi, I have a search form that looks like this. (I posted this problem yesterday, and I got a helpful response on how to do this in javascript, but I'd like to try to do it in Ruby on Rails. I'd like to try to understand what's going on with this error message.)

    <div id="search_box" class="search_box">       <% form_for :search_term, :url => { :action => :search} do |f| %>       <%= f.text_field 'search_term' %>       <%= submit_tag 'Search' %>       <% end %>     </div>

After a search is done, I'd like for a user to be able to do that search again just by clicking on a link. Here's my try at that:

<%= link_to(truncate(recent_search.search_term, 40), {:controller => 'admin', :action => 'search', :search_term => recent_search.search_term }, :method => :post ) %>

I get this error:

undefined method `stringify_keys!' for "test search":String

What I think is happening here is that I'm trying to submit the key to a hash, rather than the value. Is that right?

Charlie

Charlie -

"test search" is the value of the form's search_term, right? i don't see how you populate recent_search. what does recent_search.search_term.inspect return?

Yes, "test search" is the value of the form's search_term. recent_search is coming out of an object in my controller -- maybe this will make it clearer. Here's the partial that I'm trying to get to render, with a link to a form submit:

<div id="pagination" class="left_pagination"><%= pagination_links(@recent_search_pages) %></div> <div id="recent_searches" class="left_column_header" >Recent Searches<div id="recent_searches" class="left_column_listing"> <% for recent_search in @recent_searches %> <div id="recent_search_item_<%= recent_search.id %>" class="recent_search_listings" >   <div class="deleted_news_search_result_title">

  <%= link_to(truncate(recent_search.search_term, 40), {:controller => 'admin', :action => 'search', :search_term => recent_search.search_term }, :method => :post ) %>

</div>

</div> <% end %> </div>

recent_search.search_term is an old search that a user did, that I pull out of the database. It it indeed being pulled out of the database -- I can see it right there on the page, because the beginning of my link_to is that string, and it renders properly. Maybe I don't understand what you're getting at.

Somehow I think this form is sending a value to a key:

> <div id="search_box" class="search_box"> > <% form_for :search_term, :url => { :action => :search} do |f| > %> > <%= f.text_field 'search_term' %> > <%= submit_tag 'Search' %> > <% end %> > </div>

And my link is sending the key, which ruby is trying to stringify. That's all I can make of that error.

Charlie

hm. maybe i'm too new to this to be useful. i'm confused that your form_for takes :search_term, and your text field inside the form does too. i thought form_for took the name of an object that _contained_ attributes whose names map to fields. so it's looking for search_term.search_term?