2011-05-06 68 views
5

我想呈現另一個視圖內的設計編輯密碼錶單,因爲我不想重複編輯pw邏輯。呈現設計編輯密碼錶格

我已經試過以下(生成設計意見後):

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

和一批上渲染似乎都給予我同樣的錯誤其他變化:

「的ActionView: :MissingTemplate在FOO#富 缺少的部分色器件/密碼/編輯...」

這種變化:

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

給了我一些希望,但出現以下錯誤:

「未定義的局部變量或方法'資源」爲#<#:0x47ef0e0>」

解決此行:

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

這使得我認爲我很接近(因爲這是我想要的形式的代碼),但不應該使用隱藏的Devise控制器的正確邏輯嗎?或者我需要在路線文件中做些什麼才能使其發揮作用?

我會離開嗎?

回答

7

試試這個:

<%= 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可能是
+1

謝謝您的回答。使用「用戶」而不是「用戶」給我一個新的錯誤信息:未定義的方法'devise_error_messages!'對於#<#:0x4b44fd0> – LennonR 2011-05-06 19:30:30

+0

包含'devise_helper.rb'文件以解決該(新)問題;或者移除該呼叫並使用您自己的錯誤報告。由於我的答案解決了你的問題,你可以接受它! – Zabba 2011-05-06 21:33:02

+0

謝謝你的工作。最後一個問題。當表單提交出錯時,它將重定向到「/ users」,而不是我提交表單的地方。接受密碼更改後,它會重定向到應用程序的索引頁面。我將如何控制這些重定向? – LennonR 2011-05-07 20:15:12