设计编辑密码页面-访问用户模型

发布于 2024-11-09 10:15:26 字数 174 浏览 4 评论 0原文

我需要自定义 Devise 编辑密码页面以包含用户模型中包含的一些详细信息。

我在网上快速浏览了一下,但找不到任何提及有权访问用户模型的视图的文档。

有办法访问它吗?

编辑:我已经得到了视图等,它专门关于在编辑密码页面中访问用户模型。我需要个性化它。

I need to customise the Devise edit password page to include a few details that are included in the User model.

I had a quick look online but couldn't find any documentation mentioning the views having access to the user model.

Is there a way to access it?

Edit: I've got the views et al, it's specifically about accessing the user model in the edit password page. I need to personalise it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小草泠泠 2024-11-16 10:15:26
= render :template => 'devise/passwords/edit', :locals => {:resource => current_user,:resource_name => User }

在视图中尝试这个
对于 devise_errors 包括 devise_helper.rb 或编写您自己的错误处理程序

= render :template => 'devise/passwords/edit', :locals => {:resource => current_user,:resource_name => User }

Try this in view
For devise_errors include devise_helper.rb or write your own error handler

悲喜皆因你 2024-11-16 10:15:26

运行此命令,它会将您的视图复制到名为“shared”(R<3)和“devise”(R3)的文件夹中。

rails g devise:views

然后您可以自定义视图。您应该能够理解这些卷中的所有内容,它们只是 Rails MVC 的内容。

如果您有特定的设备型号,则应按名称指定该型号:

rails g devise:views users

Run this and it will copy your views to a folder called 'shared' for R<3 and 'devise' for R3.

rails g devise:views

You can then customize the views. You should be able to understand everything in those volders it's just Rails MVC stuff.

If you have a specific devise model you should specific the model by name:

rails g devise:views users
夜司空 2024-11-16 10:15:26

rails generated devise:views users

这将为用户模型生成视图。然后您可以手动编辑您想要的内容。

rails generate devise:views users

This will generate the views for the user model. You can then manually edit the ones you want.

一世旳自豪 2024-11-16 10:15:26

查看 github 上的 devise Wiki ( https://github.com/plataformatec/devise/wiki ),此外,您可能想要做的是在应用程序主目录中运行以下命令。
rails g devise:views 或对于特定模型 rails g devise:views modelName

它将在 app/views/devise 下创建视图树。

在视图中,将对象引用为 resource

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
...

您可以安全地删除不需要覆盖的视图,如果您想对视图使用 haml 或 slim ,也可以,请参阅这个维基页面 => https://github.com/plataformatec/ devise/wiki/操作方法:创建 Haml 和 Slim 视图

Check out the devise Wiki on github ( https://github.com/plataformatec/devise/wiki ), furthermore what you prolly want to do is run the following command in your app home.
rails g devise:views or for a specific model rails g devise:views modelName

that will create the tree of views under app/views/devise.

In the views, refer to the object as resource

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
...

You can safely delete the views that you don't need to over ride, if you want to use haml or slim for views, that is fine too, see this wiki page => https://github.com/plataformatec/devise/wiki/How-To:-Create-Haml-and-Slim-Views

眼眸印温柔 2024-11-16 10:15:26

我也想做同样的事情。我暂时将 resource.inspect 放入视图中,发现它是一个 User 实例,除了 reset_password_token 之外,所有属性都为 nil。鉴于此,我使用暴力访问了相应的用户记录:

User.find_by_reset_password_token(resource.reset_password_token)

或者更通用:

resource.class.find_by_reset_password_token(resource.reset_password_token)

您可以直接在视图中使用它,或者如果您要覆盖 Devise 控制器,则将其分配给控制器中的实例变量。请注意,如果令牌无效,它将返回 nil。 (看来 Devise 在用户提交表单之前不会检查令牌的有效性,因此您可以使用无效令牌访问此视图。)

更新 03/2014

从 devise 3.1 开始,您需要在查找之前消化令牌:

resource.class.find_by_reset_password_token(Devise.token_generator.digest(resource.class, :reset_password_token, resource.reset_password_token))

I wanted to do the same thing. I temporarily put resource.inspect into the view, and saw that it was a User instance with all attributes nil except for reset_password_token. Given that, I accessed the corresponding User record using brute force:

User.find_by_reset_password_token(resource.reset_password_token)

Or to be more generic:

resource.class.find_by_reset_password_token(resource.reset_password_token)

You can use that directly in view, or assign it to an instance variable in the controller if you're overriding the Devise controller. Be aware that it will return nil if the token is invalid. (It seems Devise doesn't check the validity of the token until after the user submits the form, so you can get to this view with an invalid token.)

Update 03/2014

As of devise 3.1, you need to digest the token before lookup:

resource.class.find_by_reset_password_token(Devise.token_generator.digest(resource.class, :reset_password_token, resource.reset_password_token))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文