简体   繁体   English

在Devise Rails 4中使用注销链接时出错

[英]Error using logout link with Devise Rails 4

I'd like to start off saying I know there are other questions on here about this however none of them are using rails 4 and I could not get their suggestions to work. 我想开始说,我知道这里还有其他问题,但是他们都没有使用rails 4,我无法得到他们的建议。 The error I am getting is "uninitialized constant HomeController" 我得到的错误是“未初始化的常量HomeController”

code in index.html.erb index.html.erb中的代码

<%if user_signed_in? %>
    <p align= "right">Hello <%=current_user.email %> <%= link_to "sign out", destroy_user_session_path, :method => :delete %></p> 

Here are the first 3 lines to application.html.erb 这是application.html.erb的前三行

<!DOCTYPE html>
<html>
<%= javascript_include_tag :defaults %>

I'm thinking it might have something to do with this line in my routes.rb file 我在想这可能与我的routes.rb文件中的这一行有关

root 'home#index'

Thanks in advance 提前致谢

you dont have home controller at app/controllers/ 您在应用程序/控制器/处没有家庭控制器

you should create app/controllers/home_controller.rb with: 您应该使用以下命令创建app / controllers / home_controller.rb:

class HomeController < ApplicationController
  def index
  end
end

for your second error: you call method email for nil(not post). 对于您的第二个错误:您将方法电子邮件称为nil(不是发布)。

问题出在我的routes.rb文件中,它应该读为“ posts#index”而不是“ home#index”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM