我正在尝试在application.html.erb的标头中包含登录名(用户名/密码)。我收到了这个错误:
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' %>
'/ 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)中,我是不知道该怎么做。有人知道怎么做吗?谢谢!
答案 0 :(得分:9)
<%= render "sessions/login", :@user => User.new %>
将呈现登录部分会话视图,即&#39; _login.html.erb&#39;在views / sessions中,并将@user
实例化为新用户,以便可以在partial中直接引用它:
form_for @user, :url => sessions_path do |f|
f.text_field :email
答案 1 :(得分:0)
在我的案例文件扩展名 rhtml 中检查您的文件扩展名,我将其更改为 html.erb 。
现在工作正常。
注意:强>
此 rhtml 扩展名的文件在 rails&lt; = 3.0.10 中正常运行。但是停止了 rails 3.1.12 的工作。所以我改变了它的扩展,如上所述。