渲染Devise编辑密码表单 [英] Rendering the Devise edit Password Form
问题描述
我试图在另一个视图中渲染Devise编辑密码表单,因为我不想复制编辑pw逻辑。
I'm trying to render the Devise edit password form within another view because I don't want to duplicate the edit pw logic.
我尝试过以下(在生成Devise视图之后):
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| %>
这让我觉得我很亲密(因为这是我想要的形式的代码),这个模板不应该使用隐藏的Devise控制器的正确逻辑吗?或者我需要在路线文件中做一些事情以使其工作吗?
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
可以是用户
my_user_model_variable
could becurrent_user
my_user_model_name
could be"User"
这篇关于渲染Devise编辑密码表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!