繁体   English   中英

我如何在Rails控制台中修复名称错误

[英]how can i fix a name error in rails console

我尝试在Twitter克隆上工作,当我运行Rails控制台并运行User.all时,我得到了

irb(main):001:0> User.all
Traceback (most recent call last):
        3: from (irb):1
        2: from app/models/user.rb:1:in `<main>'
        1: from app/models/user.rb:5:in `<class:User>'
NameError (undefined local variable or method `“Relationship”' for User (call 'User.connection' to establish a connection):Class)
Did you mean?  relation

这是我的user.rb代码

class User < ApplicationRecord
    has_many :tweets


    has_many :followers, :class_name => “Relationship”, :foreign_key => “user_id”
    has_many :following, :class_name => “Relationship”, :foreign_key => “follower_id”
end

我该如何解决我的错误

正在按照https://codeburst.io/making-a-twitter-clone-in-raw-html-with-ruby-on-rails-and-a-lil-javascript-270a5e227cb2上的步骤进行操作

如果您准确地粘贴了正在运行的代码,则存在一个相当细微的问题:引号的类型。 此处使用的引号:

“Relationship”

实际上与Ruby期望的字符不同:

"Relationship"

如果您粘贴教程中的代码,则可能会出现此问题。 网页上经常使用这种其他类型的引号。

暂无
暂无

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

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