# Help with submitting a form by clicking on a link

**URL:** <https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354>\
**Category:** Rails\
**Created:** [June 8, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354 "2007-06-08T22:20:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [June 8, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354/1 "2007-06-08T22:20:20Z")

</div>

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 %\>

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

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [June 8, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354/2 "2007-06-08T23:56:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [June 9, 2007, 12:16am UTC](https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354/3 "2007-06-09T00:16:34Z")

</div>

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:

\<%= pagination\_links(@recent\_search\_pages) %\>

Recent Searches
\<% for recent\_search in @recent\_searches %\>

\<%= link\_to(truncate(recent\_search.search\_term, 40), {:controller =\>  
‘admin’, :action =\> ‘search’, :search\_term =\>  
recent\_search.search\_term }, :method =\> :post ) %\>

\<% end %\>

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 %\>

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

Charlie

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [June 9, 2007, 1:33am UTC](https://www.ruby-forum.com/t/help-with-submitting-a-form-by-clicking-on-a-link/106354/4 "2007-06-09T01:33:41Z")

</div>

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?
