gpt4 book ai didi

ruby-on-rails-3 - Rails 3 从另一个 Controller 渲染部分(错误:ActionView::MissingTemplate)

转载 作者:行者123 更新时间:2023-12-04 17:38:55 26 4
gpt4 key购买 nike

我正在尝试在 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" 

更新:这是我的 session Controller :
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

我在其他帖子中看到这可能是由于没有在 Controller 操作中定义变量,但由于这是一个 session ,并且它在 application.html.erb (application_controller.rb) 中,我不确定如何去做这个。有人知道怎么做吗?谢谢!

最佳答案

<%= render "sessions/login", :@user => User.new %>
将呈现 session View 的登录部分,即 View / session 中的“_login.html.erb”并实例化 @user给新用户,以便它可以在部分中直接引用为:

form_for @user, :url => sessions_path do |f| 
f.text_field :email

关于ruby-on-rails-3 - Rails 3 从另一个 Controller 渲染部分(错误:ActionView::MissingTemplate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9304368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com