Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Devise - edit_user_registration_path

with Rails there is the path, edit_user_registration_path to allow users to edit their profile.

I'm setting up my own Account Control to present the user with a better UI to edit their profile etc.. which is routed at /account/profile, /account/notices, etc....

Problem is this URL, /users/edit still works and takes users to the DEVISE edit page.

How can I have that always go to the new edit page /account/profile

Thanks

like image 744
AnApprentice Avatar asked Nov 07 '10 00:11

AnApprentice


3 Answers

This is probably the worst part about devise is making a custom edit profile path. The reason for this is when you try to update your resource, it's going to send you back to the default path for editing the user, that is if you get errors.

What I would suggest is that you keep the default users/edit path and then edit assocations, not the actual resources. Otherwise you are going to have to dig into the gem and rewrite the paths of how users are edited.

This is what I did.

In your User model user.rb

has_one :profile
has_many :notices

Then you can have a notices and profiles controller where you edit those and not the user or the resource which is what you made with the devise helpers and will make it harder to customize. Make a hidden_field f.hidden_field :user_id, :value => current_user.id for those forms and it will save the user when you create them and update them etc...

like image 152
thenengah Avatar answered Nov 09 '22 12:11

thenengah


As of the latest Devise release (specifically this commit), you can now specify a custom path for the edit profile action via path_names:

devise_for :users, path_names: { edit: 'profile' }
like image 40
Louis Simoneau Avatar answered Nov 09 '22 12:11

Louis Simoneau


A simpler way is just to create a ProfilesController, and in your routes, just define "resource :profile". Then you just define the "edit" and "update" methods and you're done.

I haven't taken it much further than the basics, but I really don't see the downside, and it's really simple in comparison to anything that's been offered here.

like image 1
elsurudo Avatar answered Nov 09 '22 13:11

elsurudo