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'' %> <label for="email_address">Email Address:</label> <%= 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Duh - forgot to mention what the problem is. The finder is returning a nil object. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 21 Nov 2007, at 07:44, Old Echo wrote:> > The partial just contains: > <%= error_messages_for ''recipient'' %> > <label for="email_address">Email Address:</label> > <%= 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 21 Nov 2007, at 07:44, Old Echo wrote: >> >> The partial just contains: >> <%= error_messages_for ''recipient'' %> >> <label for="email_address">Email Address:</label> >> <%= 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. > > > FredHooray, 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Nov 2007, at 06:31, Old Echo wrote:> > Frederick Cheung wrote: >> On 21 Nov 2007, at 07:44, Old Echo wrote: >>> >>> The partial just contains: >>> <%= error_messages_for ''recipient'' %> >>> <label for="email_address">Email Address:</label> >>> <%= 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]?Yes, that''s the way it works. Fred
Frederick Cheung wrote:> On 22 Nov 2007, at 06:31, Old Echo 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. > > FredAwesome - thank you. You''ve cleared up a great mystery for me. : ) Happy Thanksgiving, kodama -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---