我試圖在我的application.html.erb頭中包含一個登錄名(用戶名/密碼)。我收到此錯誤:Rails 3渲染部分從另一個控制器(錯誤:ActionView :: MissingTemplate)
Missing partial /login with {:handlers=>[:rjs, :builder, :rhtml, :erb, :rxml], :locale=>[:en, :en], :formats=>[:html]} in view paths "/app/views"
,當我在做我的application.html.erb此調用發生這種情況:
<%= render '/login' %>
「/登錄」我的routes.rb中被定義爲:
match '/login' => "sessions#new", :as => "login"
更新:這是我的會話控制器:
class SessionsController < ApplicationController
def create
if user = User.authenticate(params[:email], params[:password])
session[:user_id] = user.id
user.last_login = Time.now
user.save
redirect_to root_path, :notice => "login successful"
else
flash.now[:alert] = "invalid login/password combination " # don't show pass + params[:password]
#render :action => "new"
redirect_to login_path, :notice => "wrong user pass"
end
end
def destroy
reset_session
redirect_to root_path, :notice => "successfully logged out"
end
end
我在其他帖子中看到,這可能是由於未在控制器操作中定義變量,但由於這是一個會話,並且位於application.html.erb(application_controller.rb)中,所以我沒有確定如何做到這一點。任何人都知道如何做到這一點?謝謝!
你的部分在哪裏?而且,爲什麼你在渲染中分配路徑路徑? – prasvin 2012-02-16 06:00:25
部分位於views/sessions/new.html.erb中。之所以我在我的調用中使用'/ login'來渲染,是因爲我想它會渲染views/sessions/new.html.erb部分。 – botbot 2012-02-16 06:15:07
查看已更新的答案 – prasvin 2012-02-16 06:37:12