The user can register, edit your profile. To edit a profile, use the same form as for registration. But when editing a profile, the user also has to enter the password and its confirmation. And if the profile is not edited by himself, but by the administrator, then he will also have to enter a password, which he, of course, does not know. So, what to do to avoid this?

PS model controller and display generated by scaffolding.

  • Does the user have a role method? of this type current_user.role.eql? ("admin") - Vetal4eg
  • There is no such method, there is a field is_stuff: boolean - Niki-Timofe

1 answer 1

You can use the popular devise solution. The device has update_without_password method:

def update @user = User.find(params[:id]) respond_to do |format| if @user .update_without_password(params[:user]) redirect_to root_url, flash[:notice] = "ok" else render action: "edit" end end end 

Or write your private method, which would allow to update the admin user without a password.

  • It is possible in more detail about the installation of the device, and then, hem set the method changed, produces: undefined method `update_without_password 'for # <User: 0x007fed947cc368> - Niki-Timofe
  • 1. gem 'devise'> Gemfile 2. bundle install 3. rails generate devise: install 4. details here github.com/plataformatec/devise - Vetal4eg
  • You can inherit devaysovskiy: class Users :: SessionsController <Devise :: SessionsController - Vetal4eg
  • I made it easier, took the method from Device and attached it to my model, but now validation does not allow to save, because it writes that the password cannot be empty or shorter than 6 characters. What can be done about it? - Niki-Timofe
  • For 6 characters it answers: validatable Do you use the update_without_password method? - Vetal4eg