# Dynamic finders, params, symbols, confusion

**URL:** <https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865>\
**Category:** Rails\
**Created:** [November 21, 2007, 8:44am UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865 "2007-11-21T08:44:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 21, 2007, 8:44am UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/1 "2007-11-21T08:44:17Z")

</div>

Hello Rubyists,  
I think I need a crash course in how the “params[]” hash works. I’m  
trying to debug this problem, and I think a large part of the issue  
stems from my lack of understanding of how params works.

Here is the offending line of code:

@recipient = Recipient.find\_by\_email\_address(params[:recipient])

This method is on a controller called Signup and is looking for a record  
in the Recipient model. The view is named “forgot\_passcode” and lives in  
the Signup views.

This is the code in the view:

\<% form\_tag :action =\> ‘send\_forgotten\_passcode’ do %\>  
\<%= render :partial =\> ‘passcode’ %\>  
\<%= submit\_tag “Submit” %\>  
\<% end %\>

“send\_forgotten\_passcode” is a method that locates a Recipient by their  
email address and sends their passcode back to them.

The partial just contains:  
\<%= error\_messages\_for ‘recipient’ %\>  
Email Address:  
\<%= text\_field ‘signup’, ‘email\_address’ %\>

I’m at my wits end and generally pretty confused on what I’m doing  
wrong. Any help would be appreciated.

Thanks,  
kodama

---

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 21, 2007, 8:45am UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/2 "2007-11-21T08:45:11Z")

</div>

Duh - forgot to mention what the problem is. The finder is returning a  
nil object.

---

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 21, 2007, 8:54am UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/3 "2007-11-21T08:54:46Z")

</div>

On 21 Nov 2007, at 07:44, Old E. wrote:

> The partial just contains:  
> \<%= error\_messages\_for ‘recipient’ %\>  
> Email Address:  
> \<%= text\_field ‘signup’, ‘email\_address’ %\>

This means that the parameter entered will be available as  
params[:signup][:email\_address] and so that’s what you need to pass to  
find\_by\_email\_address  
If you look at the log file you can see the params hash for each  
request.

Fred

---

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 22, 2007, 7:31am UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/4 "2007-11-22T07:31:49Z")

</div>

Frederick C. wrote:

> On 21 Nov 2007, at 07:44, Old E. wrote:
> 
> > The partial just contains:  
> > \<%= error\_messages\_for ‘recipient’ %\>  
> > Email Address:  
> > \<%= text\_field ‘signup’, ‘email\_address’ %\>
> 
> This means that the parameter entered will be available as  
> params[:signup][:email\_address] and so that’s what you need to pass to  
> find\_by\_email\_address  
> If you look at the log file you can see the params hash for each  
> request.
> 
> Fred

Hooray, it worked! Thank you so much. So, is that how params works? How  
you define the fields in the view is what gets returned? E.g. if the  
text field had been \<%= ‘blog\_post’, ‘title’ %\>, if you wanted to get at  
the user input, you’d use params[:blog\_post][:title]?

Thanks again - I think I generally have an okay knowledge of how Rails  
works, but params has so far been very mystical for me.

---

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 22, 2007, 2:52pm UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/5 "2007-11-22T14:52:58Z")

</div>

On 22 Nov 2007, at 06:31, Old E. wrote:

> > params[:signup][:email\_address] and so that’s what you need to pass  
> > you define the fields in the view is what gets returned? E.g. if the  
> > text field had been \<%= ‘blog\_post’, ‘title’ %\>, if you wanted to  
> > get at  
> > the user input, you’d use params[:blog\_post][:title]?

Yes, that’s the way it works.

Fred

---

<div class="post-metadata">

**Author:** ![kodama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kodama](https://www.ruby-forum.com/u/kodama)\
**Post date:** [November 22, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/dynamic-finders-params-symbols-confusion/120865/6 "2007-11-22T21:30:44Z")

</div>

Frederick C. wrote:

> On 22 Nov 2007, at 06:31, Old E. wrote:
> 
> > > params[:signup][:email\_address] and so that’s what you need to pass  
> > > you define the fields in the view is what gets returned? E.g. if the  
> > > text field had been \<%= ‘blog\_post’, ‘title’ %\>, if you wanted to  
> > > get at  
> > > the user input, you’d use params[:blog\_post][:title]?
> 
> Yes, that’s the way it works.
> 
> Fred

Awesome - thank you. You’ve cleared up a great mystery for me. : )

Happy Thanksgiving,  
kodama
