Ruby on rails 4 Rails:未初始化常量(NameError)

Ruby on rails 4 Rails:未初始化常量(NameError),ruby-on-rails-4,railstutorial.org,Ruby On Rails 4,Railstutorial.org,我被困在Rails教程的第11章(“第11.2.5节使用Ajax的工作跟随按钮”)。我越来越 relationships_controller_spec.rb:3:in `<top (required)>': uninitialized constant RelationshipsController (NameError) 以下是控制器(/sample\u app/app/controllers/relatonships\u controller.rb)本身: 类关系控制器

我被困在Rails教程的第11章(“第11.2.5节使用Ajax的工作跟随按钮”)。我越来越

relationships_controller_spec.rb:3:in `<top (required)>': uninitialized constant RelationshipsController (NameError)
以下是控制器(/sample\u app/app/controllers/relatonships\u controller.rb)本身:

类关系控制器

我做错了什么?

您的文件名是什么?在Rails中,这可能很重要。确保您的控制器实际被称为
relationships\u controller.rb


文件名或类通常称为单数形式,而另一种称为复数形式,但似乎缺少了一个“r”。比如你的文件名是
relationships\u controlle.rb

你的文件名有误:/relationships,relat和onships之间没有i

控制器文件的名称拼写正确吗<代码>应用程序/控制器/关系\u controller.rb
。克里斯·彼得斯:我怀疑也许你漏掉了最后一个“r?”——这一定是我写这篇文章时的打字错误。我现在在上面的错误消息中添加了“r”。所以,不幸的是,问题似乎不是由于文件名。谢谢-但这似乎是我的文章中的一个打字错误。错误消息包括“r”。我更正了帖子。但我仍然有这个问题。事实上,您的文件名中有另一个输入错误:/relatonships,relat和onships之间没有I。@frandroid:是的,这就是原因-谢谢!如果你把这个放在另一个帖子里,我会接受t。
require 'spec_helper'

describe RelationshipsController do
let(:user) {FactoryGirl.create(:user)}
let(:other_user) {FactoryGirl.create(:user)}

before {sign_in user, no_capybara: true}

describe "create a relationship with Ajax" do

it "should increment the Relationship count" do
  expect do
    xhr :post, :create, relationship: { followed_id: other_user.id}
  end.to change(Relationship, :count).by(1)
end

it "should respond with success" do
  xhr :post, :create, relationship: {followed_id: other_user.id}
  expect(response).to be_success
end
end

describe "destroying a relationship with Ajax" do

before {user.follow!(other_user)}

let(:relationship) do
  user.relationships.find_by(followed_id: other_user.id)
end

it "should decrement the Relationship count" do
  expect do
    xhr :delete, :destroy, id: relationship.id
  end.to change(relationship, :count).by(-1)
end

it "should respond with success" do
  xhr :delete, :destroy, id: relationship.id
  expect(response).to be_success
end
end
end
class RelationshipsController < ApplicationController
before_action :signed_in_user

def create
@user = User.find(params[:relationship][:followed_id])
current_user.follow!(@user)
#redirect_to @user replaced with the code below:
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)
#redirect_to @user replaced with the code below:
respond_to do |format|
  format.html {redirect_to @user}
  format.js
end
end
end