Put this in your view form:
<%= f.password_field :password %> <%= f.password_field :password_confirmation %>
And this is in your user model:
validates_confirmation_of :password
Now, to prevent unwanted initializations in your controller, add the following to your model:
attr_accessible :attribute1, attribute2
Now these attributes will be the only attributes that can be set through the so-called mass assignment.
Jaime bellmyer
source share