ruby on rails - Simple string comparison not working! Frustration ensues -
i cannot seem figure out why comparison not working:
if params[:password].to_s == params[:conf_password].to_s #do else #do else
the result false, executing else block... know why?
edit: checking output shows 2 parameters identical. "password" collected using 'form_for' , "conf_password" password_field_tag.
if "conf_password" included in 'form_for' no such method error thrown, because there no column conf_password in model. perhaps there better way of collecting param, may solve issue.
some log output regarding params.
params: {"password"=>"1234567", "company"=>"company1", "companykey"=>"ckey2"}, "conf_password"=>"1234567",
code these values
<tr> <td> <%= label_tag(:password, "password") %> </td> <td> <%= f.password_field :password %> </td> </tr> <tr> <td> <%= label_tag(:conf_password, "confirm password") %> </td> <td> <%= password_field_tag(:conf_password) %> </td> </tr>
it seems me should not accessing :password
, :conf_password
same way :password
parameter within hash while :conf_password
not.
when declare form_for define hash contains :password
, have access :password
-parameter new object(params[:object]).password
. able access parameter params[:object][:password]
well.
untested example form based on copy-paste coding
<%= form_for @person |f| %> <%= f.label :first_name %>: <%= f.text_field :first_name %><br /> <%= f.label :password %>: <%= f.text_field :password %><br /> <%= f.submit %> <% end %>
untested example controller based on deduction not knowledge
if person.create(params[:person]).password == 'foobar' # go on else # fail end
for more though out description see api: http://api.rubyonrails.org/classes/actionview/helpers/formhelper.html
Comments
Post a Comment