Skip to content

Instantly share code, notes, and snippets.

@mwoods79
Last active December 11, 2015 06:28
Show Gist options
  • Save mwoods79/4559590 to your computer and use it in GitHub Desktop.
Save mwoods79/4559590 to your computer and use it in GitHub Desktop.

If you need to add the ability change passwords in the "admin" panel of boilerplate.

Add the password and password_confirmation to the User Decorator

# app/decorators/inherited_resources/user_decorator.rb
module InheritedResources
  class UserDecorator < Decorator
  # ...
  
    def form_attributes
      [:email, :first_name, :last_name, :birthday, :gender, :current_city,
       :hometown, :avatar, :password, :password_confirmation]
    end

  #...
end

Then disable password validate for update, only if they don't supply a new paswword

class Admin::UsersController < Admin::ResourceController
  add_crumb "Users", :admin_users_url

  def update
    if params[:user][:password].empty?
      @user = User.find(params[:id])
      @user.update_without_password(params[:user])
      update!{ edit_resource_url }
    else
      update!{ edit_resource_url }
    end
  end
end

DONE! :)

@code0100fun
Copy link

I needed this in LookLites thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment