呈现设计编辑密码表单 [英] Rendering the Devise edit Password Form

查看:20
本文介绍了呈现设计编辑密码表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在另一个视图中呈现设计编辑密码表单,因为我不想复制编辑密码逻辑.

I'm trying to render the Devise edit password form within another view because I don't want to duplicate the edit pw logic.

我尝试了以下操作(在生成设计视图之后):

I've tried the following (after generating the Devise views):

<%= render 'devise/passwords/edit' %>
<%= render 'devise/passwords/form' %>

渲染的许多其他变体似乎都给了我同样的错误:

And a number of other variations on render that all seem to give me the same error:

"ActionView::MissingTemplate in foo#foo缺少部分设计/密码/编辑..."

"ActionView::MissingTemplate in foo#foo Missing partial devise/passwords/edit..."

这种变化:

  <%= render :file => 'devise/passwords/edit.html.erb' %>

给了我一些希望,但出现以下错误:

Gave me some hope but the following error:

"未定义的局部变量或方法`resource' for #<#:0x47ef0e0>"

"undefined local variable or method `resource' for #<#:0x47ef0e0>"

围绕这条线:

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>

这让我觉得我很接近(因为这是我想要的表单中的代码)但该模板不应该使用隐藏的设计控制器中的正确逻辑吗?或者我需要在路由文件中做些什么才能让它工作?

That makes me think I'm close (as that is code from the form that I want) but shouldn't that template be using the correct logic from the hidden Devise controller? Or do I need to do something in the routes file to get this to work?

我走了吗?

推荐答案

试试这个:

<%= render :template => 'devise/passwords/edit', 
                        :locals => { 
                          :resource => my_user_model_variable, 
                          :resource_name => my_user_model_name } %>

地点:

  • my_user_model_variable 可以是 current_user
  • my_user_model_name 可以是 "User"
  • my_user_model_variable could be current_user
  • my_user_model_name could be "User"

这篇关于呈现设计编辑密码表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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