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.
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.
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.
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.
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]?
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.