简体   繁体   中英

Rails Devise User Profile Page/Dashboard

I want to create a User 'profile page' with links to other pages where they can update their account info. Unfortunately the default 'edit' page that comes out of the box with devise is not enough for what I need.

For example, I'd want it to look something like this with the routes:

'/profile'
'/profile/edit' <-- this would be the default devise edit password, name etc.
'/profile/documents'
'/profile/progress'

But I'm not sure how to approach this when using Devise. I already have Devise working out of the box, with the default edit page, but I essentially just want to add extra views for Users to upload files etc.

Any help on this would be really appreciated!

There can be 2 solutions to this:

First:

With Devise, you can customize controllers/views:

For example in your case, you will do something like this in your routes.rb :

devise_for :users, controllers: {registrations: 'profiles'}

In simple terms, this will tell devise to set the profiles controller as the registrations controller.

You can go through this devise readme section for more detailed information.

Second:

If you don't want to write custom controller and extend the form to new fields, then you can simply edit the registrations/edit.html.erb page with your new fields (like image upload etc) and whitelist/permit these additional params with this in your ApplicationController :

class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    # for signup
    devise_parameter_sanitizer.permit(:sign_up, keys: [:image])

    # for update
    devise_parameter_sanitizer.permit(:account_update, keys: [:image])
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM