Devise User editing from rails_admin

1,228 views
Skip to first unread message

ejmm320

unread,
Jan 6, 2012, 2:02:51 PM1/6/12
to rails_admin
Hi, i have this situation: i'm managing the CRUD operations over the
model Users through rails_admin and the problem is when somebody wants
to change some user data like: email or username and keep unchanged
the password and password_confirmation, the change over the record
fails. Because i'm working with Devise, i read the Devise wiki and i
found a solution for edit fields without changing password, it says:

if params[:user][:password].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end

So i decided to try with my rails_admin.rb to look like this:

config.model Usuario do
# Found columns:
field :nombre_usuario, :string
field :email, :string
field :password, :password
field :password_confirmation, :password
field :activo, :boolean
# Found associations:
field :roles, :has_and_belongs_to_many_association

#Custom labels
object_label_method do
:mostrar_nombre_usuario
end

# Sections:
list do; end
export do; end
show do; end
edit do; end
create do;
include_fields :password, :password_confirmation
end
update do;
exclude_fields :password, :password_confirmation
end
end

This code hide the fields in edit view, but nothing happens if i try
to update the other fields.

Could someone point me in the right direction?

Thanks in advance.

ejmm320

unread,
Jan 6, 2012, 4:12:25 PM1/6/12
to rails_admin
Sorry, it's my fault... my problem isn't related with rails_admin, is
the use of :validatable in devise user model who forces to change
password any time to do an update :).

Greetings.

ejmm320

unread,
Jan 6, 2012, 4:51:14 PM1/6/12
to rails_admin
We realize that the only way to make a change in user fields without
change password is through update_attributes, how can i do that only
for the edit/update view in rails:admin? or your recommend avoid using
rails_admin to manage Users? should i do my own controllers/views?

Benoit Bénézech

unread,
Jan 9, 2012, 4:28:20 AM1/9/12
to rails...@googlegroups.com
In DummyApp User:

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

I tried, everything works as expected, with :validatable.

I can update email without changing password/password_confirmation.

ejmm320

unread,
Jan 9, 2012, 9:31:13 AM1/9/12
to rails...@googlegroups.com
Benoit thanks 4 the quick answer.

I upgraded to Devise 2, but nothing changes still i can't edit user data without providing a password and password confirmation in rails_admin, i'm using devise_security_extension to save old_passwords.

I'm wondering if the use of that feature to save old passwords is the cause of my headache, but i need to save the last 5 passwords and avoid duplicates.

Please try activating those features (devise_security_extension) in DummyApp and try again to edit some fields.

Thanks!

ejmm320

unread,
Jan 9, 2012, 9:57:06 AM1/9/12
to rails...@googlegroups.com
Sorry Benoit, now it works!

The problem was in the Users model... i have validates_format_of :password, :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/ and obviously leaving the field in blank doesn't match at all, now i'm gonna try in devise config with: config.password_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/ hoping that it should do the trick.

As usual many thanks for ur time and keep with the excelent job!

Thanks!
Reply all
Reply to author
Forward
0 new messages