Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails教程第11章错误“;未初始化的常量用户::关系“;_Ruby On Rails_Syntax Error_Railstutorial.org - Fatal编程技术网

Ruby on rails Rails教程第11章错误“;未初始化的常量用户::关系“;

Ruby on rails Rails教程第11章错误“;未初始化的常量用户::关系“;,ruby-on-rails,syntax-error,railstutorial.org,Ruby On Rails,Syntax Error,Railstutorial.org,我一直收到这个错误 uninitialized constant User::Relationships 当学习rails教程的第11章时 以下是在登录浏览器时尝试访问主页时发生的全部错误 Extracted source (around line #11): 8: </a> 9: <a href="<%= followers_user_path(@user) %>"> 10: <st

我一直收到这个错误

   uninitialized constant User::Relationships
当学习rails教程的第11章时

以下是在登录浏览器时尝试访问主页时发生的全部错误

    Extracted source (around line #11):

8:          </a>
9:          <a href="<%= followers_user_path(@user) %>">
10:         <strong id="followers" class="stat">
11:             <%= @user.followers.count %>
12:         </strong>
13:         followers
14:     </a>
发生错误的页面如下所示:

<% @user ||= current_user %>
<div class = "stats">
<a href ="<%= following_user_path(@user)%>">
    <strong id="following" class="stat">
        <%= @user.followed_users.count %>
    </strong>
    following
</a>
<a href="<%= followers_user_path(@user) %>">
    <strong id="followers" class="stat">
        <%= @user.followers.count %>
    </strong>
    followers
</a>
</div>

当我删除第二部分时,第二个块之前的第一部分代码可以完美地工作。只是“追随者”关系由于某种原因没有建立起来。我在控制台中玩过它,它没有呼叫,而user.u用户可以工作。我已经玩了四个小时了,把桌子扔了,又重新组装了,但我不能让它工作

我以前试过查看堆栈溢出,发现如下:

但这些解决方案都没有起到作用。谢谢你的帮助

您有一个输入错误:

has_many :reverse_relationships, foreign_key: "followed_id",
                                 class_name: "Relationships",
将最后一位更改为
类名:“关系”

class RelationshipsController < ApplicationController
before_filter :signed_in_user

def create
  @user = User.find(params[:relationship][:follower_id])
  current_user.follow!(@user)
  respond_to do |format|
    format.html { redirect_to @user }
    format.js
  end
end

def destroy
  @user = Relationship.find(params[:id]).followed
  current_user.unfollow!(@user)
  respond_to do |format|
    format.html { redirect_to @user }
    fromat.js
  end
end
 resources :users do
   member do
     get :following, :followers
   end
 end
<% @user ||= current_user %>
<div class = "stats">
<a href ="<%= following_user_path(@user)%>">
    <strong id="following" class="stat">
        <%= @user.followed_users.count %>
    </strong>
    following
</a>
<a href="<%= followers_user_path(@user) %>">
    <strong id="followers" class="stat">
        <%= @user.followers.count %>
    </strong>
    followers
</a>
</div>
has_many :reverse_relationships, foreign_key: "followed_id",
                                 class_name: "Relationships",