LJ-03
LJ-03

Reputation: 49

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!

Upvotes: 1

Views: 617

Answers (1)

cdadityang
cdadityang

Reputation: 543

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

Upvotes: 1

Related Questions