设计 - 自定义用户编辑页面 [英] devise - Customizing the User Edit Pages

查看:262
本文介绍了设计 - 自定义用户编辑页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前与设计& rails 3有一个页面的用户编辑页面:/ users / edit



我想将其拆分为更好的UI部分,如:

  / account / settings 
/ account / password
/ account / notice
/ account / disable

此外,我想要求用户输入当前密码,当用户想要更改密码。



为了实现这一点,这是否需要一个新的控制器,还是可以通过路由来处理?



此外,编辑页面现在居住在这里:app / views / devise / registrations



您是否建议在这里添加这些页面?或者/ app / views / users?



谢谢

解决方案

这里有多个选项。我会选择第一个选项,因为它似乎更符合你想要做的事情。


  1. 通过继承它来覆盖devise的注册控制器,并更新相应的视图和路由。以下是设计师的网站说明的内容:


    配置控制器



    如果视图
    级别的自定义功能还不够,您可以自定义
    每个控制器按照这些
    步骤:



    1)创建您的自定义控制器,
    示例一个Admins :: SessionsController: / p>

    class Admins :: SessionsController< Devise :: SessionsController
    end



    2)告诉路由器使用这个
    控制器:



    devise_for:admins:controller => {:sessions =>admins / sessions}



    3)而且,由于我们更改了
    控制器,它不会使用
    devise / sessions视图,所以记住
    将devise / sessions复制到
    admin / sessions。



    记住,Devise使用flash
    消息让用户知道登录
    是否成功或失败。 Devise
    希望您的应用程序可以调用
    flash [:notice]和flash [:alert]


    li>

  2. 使用用户控制器并在其中添加相应的视图(不是我的选择)



currently with devise & rails 3 there is a one page user edit page: /users/edit

I would like to split that out into sections for a better UI, something like:

/account/settings
/account/password
/account/notices
/account/disable

Also, I'd like to require the user to enter their current password when a user wants to change their password.

With devise, to make this happen, does this require a new controller, or can this all be handled with routes?

Also, currently, the edit page lives here: app/views/devise/registrations

Do you recommend adding these pages there? Or in /app/views/users ?

Thanks

解决方案

You have multiple options here. I would go with the first option as it seems to more naturally fit what you are trying to do.

  1. Override devise's registrations controller by inheriting from it, and update the corresponding views and routes. Here is what devise's site says about this:

    Configuring controllers

    If the customization at the views level is not enough, you can customize each controller by following these steps:

    1) Create your custom controller, for example a Admins::SessionsController:

    class Admins::SessionsController < Devise::SessionsController end

    2) Tell the router to use this controller:

    devise_for :admins, :controllers => { :sessions => "admins/sessions" }

    3) And since we changed the controller, it won’t use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".

    Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.

  2. Use the User controller and add actions there with corresponding views (not my choice)

这篇关于设计 - 自定义用户编辑页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆