Rails - Devise - edit_user_registration_path

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

I set up my own user account controls to provide the user with a better user interface for editing their profile, etc., which is routed to / account / profile, / account / notice, etc.

The problem is that this url, / users / edit is still working and leads users to the DEVISE edit page.

How can I make it always go to the new edit page / account / profile

thanks

+6
ruby-on-rails ruby-on-rails-3 devise
source share
4 answers

This is probably the worst part in development - this is creating a custom edit profile path. The reason for this is that when you try to update your resource, it will send you back to the default path for editing the user, that is, if you get errors.

What I would like to suggest is that you save the default path / edit the path and then edit the associations, not the actual resources. Otherwise, you will have to dig up a gem and rewrite user editing paths.

This is what I did.

In the user model user.rb

 has_one :profile has_many :notices 

Then you can have a notices and profiles controller where you edit the ones, not the user or resource , which you did with the help of the program helpers, and this will make configuration difficult. Create hidden_field f.hidden_field :user_id, :value => current_user.id for these forms and it will save the user when creating it and update it, etc.

+5
source share

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

 devise_for :users, path_names: { edit: 'profile' } 
+4
source share

An easier way is to simply create a ProfilesController, and simply define "resource: profile" on your routes. Then you simply define the change and update methods, and you're done.

I did not use it much further than the basics, but I really do not see a flaw, and it is really simple compared to what was suggested here.

0
source share

Decision:

 def update self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) if update_resource(resource, account_update_params) yield resource if block_given? if is_flashing_format? flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? :update_needs_confirmation : :updated set_flash_message :notice, flash_key end sign_in resource_name, resource, :bypass => true respond_with resource, :location => after_update_path_for(resource) else clean_up_passwords resource #Add a conditional redirect depending on where the controller was called from if URI(request.referer).path == '/users/edit' respond_with resource else redirect_to after_update_path_for(resource), :flash => { :alert => "Please enter your password" } end end end 
0
source share

All Articles