简体   繁体   English

Rails Devise 用户配置文件页面/仪表板

[英]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.不幸的是,带有 devise 的默认“编辑”页面不足以满足我的需要。

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.但是我不确定在使用 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.我已经有 Devise 开箱即用,默认编辑页面,但我基本上只是想为用户添加额外的视图来上传文件等。

Any help on this would be really appreciated!对此的任何帮助将不胜感激!

There can be 2 solutions to this:可以有两种解决方案:

First:第一的:

With Devise, you can customize controllers/views:使用 Devise,您可以自定义控制器/视图:

For example in your case, you will do something like this in your routes.rb :例如,在您的情况下,您将在您的routes.rb中执行以下操作:

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

In simple terms, this will tell devise to set the profiles controller as the registrations controller.简单来说,这将告诉 devise 将配置文件 controller 设置为注册 controller。

You can go through this devise readme section for more detailed information.您可以通过devise 自述文件部分了解更多详细信息。

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 :如果您不想编写自定义 controller 并将表单扩展到新字段,那么您只需使用新字段(如图像上传等)编辑registrations/edit.html.erb页面并将这些附加参数列入白名单/允许这在你的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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