设计编辑密码页面-访问用户模型
我需要自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在视图中尝试这个
对于 devise_errors 包括
devise_helper.rb
或编写您自己的错误处理程序Try this in view
For devise_errors include
devise_helper.rb
or write your own error handler运行此命令,它会将您的视图复制到名为“shared”(R<3)和“devise”(R3)的文件夹中。
然后您可以自定义视图。您应该能够理解这些卷中的所有内容,它们只是 Rails MVC 的内容。
如果您有特定的设备型号,则应按名称指定该型号:
Run this and it will copy your views to a folder called 'shared' for R<3 and 'devise' for R3.
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 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.
查看 github 上的 devise Wiki ( https://github.com/plataformatec/devise/wiki ),此外,您可能想要做的是在应用程序主目录中运行以下命令。
rails g devise:views
或对于特定模型rails g devise:views modelName
,它将在 app/views/devise 下创建视图树。
在视图中,将对象引用为
resource
您可以安全地删除不需要覆盖的视图,如果您想对视图使用 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 modelrails g devise:views modelName
that will create the tree of views under app/views/devise.
In the views, refer to the object as
resource
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
我也想做同样的事情。我暂时将
resource.inspect
放入视图中,发现它是一个 User 实例,除了reset_password_token
之外,所有属性都为nil
。鉴于此,我使用暴力访问了相应的用户记录:或者更通用:
您可以直接在视图中使用它,或者如果您要覆盖 Devise 控制器,则将其分配给控制器中的实例变量。请注意,如果令牌无效,它将返回 nil。 (看来 Devise 在用户提交表单之前不会检查令牌的有效性,因此您可以使用无效令牌访问此视图。)
更新 03/2014
从 devise 3.1 开始,您需要在查找之前消化令牌:
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 attributesnil
except forreset_password_token
. Given that, I accessed the corresponding User record using brute force:Or to be more generic:
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: