[英]render gives missing template error
缺少模板用戶/注冊/新用戶:
{ :locale=>[:en],
:formats=>[:html],
:handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]
下列的
redirect_to new_user_registration_url
但是工作正常
render new_user_registration_url
給出以上錯誤。
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user, new_record = User.find_or_create(request.env["omniauth.auth"], current_user)
if @user.persisted?
if new_record
sign_in @user
redirect_to basic_profile_detail_path
else
sign_in_and_redirect @user, :event => :authentication
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
end
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
render new_user_registration_url
end
end
end
這是我的 controller,但是在保存 facebook 身份驗證數據之前,我需要向用戶詢問聯系電話,並且需要從@user 數據填寫表格的 rest。 因此我不能在這種情況下使用重定向。
Missing template users/registrations/new
意味着您必須在app/views/users/registrations/
下創建一個名為new.html
的模板文件。 (參見例外中的formats
)。
盡管如此,正如@Marek Lipka 所說,您誤用了渲染,因此您應該查看以下指南。
90% 的時間我看到這個錯誤是因為我應該使用
redirect_to '/some-unique-url-in-my-app`
代替
render '/some-unique-url-in-my-app`
其余時間是因為沒有與應用程序期望找到的內容匹配的html.erb
文件。 例如,如果您render "articles/show"
,那么您的應用程序將期望找到一個名為app/views/articles/show.html.erb
還有一個很好的例子在這里
我在將舊的 Rails 2.3 應用程序升級到 Rails 7 時遇到了同樣的問題。
也許您只需要從模板文件中刪除擴展名。
舊的 Rails 2.3 代碼是:
render :template => 'companies/list.erb' and return
對我有用的 Rails 7 代碼是:
render template: 'companies/list' and return
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.