Dynamic finders, params, symbols, confusion

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

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

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

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.

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

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