I am using ActiveAdmin as my administration backend in my rails app. Basically, I have an admin_user
and a user
model.
When I create a new us
You can validate the password only on create because bcrypt when updating will still validate password presence.
class User
validate :password, :password_confirmation, presence: true, on: :create
end
In my opinion this is much simpler while causing no risk, and allows you to use a single partial form for create and update routes with an if statement showing/not showing password input field like so:
<%= form_for(user, url: users_path) do |form| %>
<%= form.label 'Name' %>
<%= form.text_field :name%>
<%= form.label 'email' %>
<%= form.text_field :email%>
<%= form.label 'Password' %>
<%= form.password_field :password%>
**<% if form.object.new_record? %>**
<%= form.label 'password_confirmation' %>
<%= form.password_field :password_confirmation%>
**<% end %>**
<%= form.submit (form.object.new_record? ? 'create' : 'update') %>