ruby on rails - Allow user profile update without password -


i need advice how model allow update of model without validation if current user admin. i've made simple user model:

create_table "user", force: true |t|     t.string   "username",     t.string   "password",     t.string   "description",     t.string   "title",     t.boolean  "disabled" end 

all users can update profile providing password again. admin has option disable user this:

<%= link_to 'disable', user_path(user, :user => {:disabled => true}), :method => :put %> 

the problem inside model have following validation:

validates :password, length: { minimum: 10 } 

after admin triggers action disable user, error shows password short , needs minimum 10 characters long. how can disable validation admin?

validates :password, length: { minimum: 10 }, :unless => :admin?  def admin?   self.role == "admin" end 

p.s: don't know how have check know if user admin. assuming have role column


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -