I cannot seem to figure out why this comparison is not working:
if params[:password].to_s == params[:conf_password].to_s
#do something
else
#do something else
The result is always false, executing the else block… Anyone know why?
Edit: Checking the output shows that the two parameters are identical. “password” is collected using a ‘form_for’ and “conf_password” from a password_field_tag.
If “conf_password” is included in the ‘form_for’ a no such method error is thrown, because there is no column conf_password in the model. Perhaps there is a better way of collecting this param, which may solve the issue.
some log output regarding params.
PARAMS: {"password"=>"1234567", "company"=>"company1", "companykey"=>"ckey2"}, "conf_password"=>"1234567",
Code to get 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 to me that you should not be accessing
:passwordand:conf_passwordthe same way as the:passwordparameter is within a hash while:conf_passwordis not.When you declare the form_for you also define the hash that contains the
:passwordand you have to access the:password-parameter withnew Object(params[:object]).password. You are able to access the parameter withparams[:object][:password]as well.Untested example form based on copy-paste coding
Untested example controller based on deduction not knowledge
For more though out description see the API: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html