Allow users to edit their account without providing a password from WikiPage doesn't work.

1,045 views
Skip to first unread message

guivinicius

unread,
Oct 15, 2010, 8:55:53 AM10/15/10
to Devise
Hi guys,

Someone here already tried the steps from wikipage to update user
attributes without password ?

http://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password

ENV:
Rails: 3.0.1
Devise: 1.1.3

I tried this strategy:

Here is an alternate strategy:

1 - Copy the registrations_controller.rb file from Devise
2 - Place this into your /app/controllers directory.
3 - In config/routes.rb add :controllers => { :registrations =>
"registrations" } to your devise_for root.
4 - Make sure you name the file registrations_controller.rb
5 - Change the first line: class Devise::RegistrationsController <
ApplicationController to class RegistrationsController <
ApplicationController
6 - Scroll to the def_update method and replace if
resource.update_with_password(params[resource_name]) with if
resource.update_attributes(params[resource_name])
7 - In /models/user.rb, add the following method:

def password_required?
new_record?
end

But still doesn't work.

Someone know how to do this properly ?

Thanks

Carlos Antonio da Silva

unread,
Oct 15, 2010, 8:59:29 AM10/15/10
to plataforma...@googlegroups.com
I believe you could just override the update_with_password in your model, to sth like this:

def update_with_password(params={})
  if params[:password].blank?
    params.delete(:password)
    params.delete(:password_confirmation) if params[:password_confirmation].blank?
  end

  update_attributes(params)
end

This way you don't need current_password.
Please let us know if that works for you, and if so, please update the wiki removing that steps and adding this one ok?
--
At.
Carlos A. da Silva

Walter Lee Davis

unread,
Oct 15, 2010, 9:13:40 AM10/15/10
to plataforma...@googlegroups.com
Is this something that might have different solutions on 2.3 and 3.0?
I still need to support both branches for the immediate future.

Thanks in advance,

Walter

Carlos Antonio da Silva

unread,
Oct 15, 2010, 9:15:16 AM10/15/10
to plataforma...@googlegroups.com
I guess this solution should work on both versions.

guivinicius

unread,
Oct 15, 2010, 9:17:22 AM10/15/10
to Devise
Didn't work yet =/

I fall in this error now.

ActiveRecord::UnknownAttributeError in Devise/
registrationsController#update

unknown attribute: current_password

app/models/user.rb:31:in `update_with_password'
app/controllers/devise/registrations_controller.rb:33:in `update



On Oct 15, 9:59 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> I believe you could just override the update_with_password in your model, to
> sth like this:
>
> def update_with_password(params={})
>   if params[:password].blank?
>     params.delete(:password)
>     params.delete(:password_confirmation) if
> params[:password_confirmation].blank?
>   end
>
>   update_attributes(params)
> end
>
> This way you don't need current_password.
> Please let us know if that works for you, and if so, please update the wiki
> removing that steps and adding this one ok?
>
>
>
>
>
> On Fri, Oct 15, 2010 at 9:55 AM, guivinicius <gui.vinic...@gmail.com> wrote:
> > Hi guys,
>
> > Someone here already tried the steps from wikipage to update user
> > attributes without password ?
>
> >http://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-ed...

Carlos Antonio da Silva

unread,
Oct 15, 2010, 9:19:25 AM10/15/10
to plataforma...@googlegroups.com
I guess you need to rollback all the changes you've done before (while following the wiki) and also remove current_password from your form.

guivinicius

unread,
Oct 15, 2010, 9:23:44 AM10/15/10
to Devise
I just removed the field current_password and works fine!

Thanks

Now I'm going to try this using a remote form in another page. heheh,
I hope it works.

Carlos Antonio da Silva

unread,
Oct 15, 2010, 9:25:07 AM10/15/10
to plataforma...@googlegroups.com
Nice.. Could you please update the wiki with this info?
I believe others would like to know this works =).

guivinicius

unread,
Oct 15, 2010, 9:27:32 AM10/15/10
to Devise
Of course.

Thanks again.

On Oct 15, 10:25 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Nice.. Could you please update the wiki with this info?
> I believe others would like to know this works =).
>
Reply all
Reply to author
Forward
0 new messages