试图告诉我这个种子错误是什么?

时间:2018-03-13 23:34:52

标签: ruby-on-rails command-line terminal

我正在创建一个与漫画书有关的RoR应用程序,并且在使用rails db:seed命令后我一直收到此错误:

rails aborted!

SyntaxError: 

/Users/cggarcia171/Desktop/environment/ComicApp/db/seeds.rb:9: syntax 
error, unexpected tLABEL
ch1 = Character.create (alias:'Doctor Manhattan', name: 'Dr.
                          ^
/Users/cggarcia171/Desktop/environment/ComicApp/db/seeds.rb:9: syntax 
error, unexpected ',', expecting end-of-input 
ate (alias:'Doctor Manhattan', name: 'Dr. Jonathan 'Jon' Ost
                          ^

这是我的一些代码:

ch1 = Character.create 
(alias:'Doctor Manhattan', 
 name: "Dr. Jonathan 'Jon' Osterman", 
 image: 'Doctor_Manhattan.jpg', 
bio: 'He was originally 
Dr. Jonathan Osterman, a nuclear physicist who in 1959 was transformed 
into one of the most supreme beings of DC Comics, after initially being 
disintegrated in an Intrinsic Field Subtractor and later reconstructing 
himself. Following his reanimation, he was immediately pressed into 
service by the United States government, who gave him the name Doctor 
Manhattan, after the Manhattan Project. He is the only character in the 
story that possesses actual superpowers.')

2 个答案:

答案 0 :(得分:1)

我在您的代码中看到至少三个错误:

  1. Ruby实际上是空白敏感的。 m (a, b)m(a, b)是完全不同的东西,第一个是语法错误(因为Ruby试图将括号解释为分组括号但(a, b)不是有效表达式)而第二个是带有两个参数的方法调用。

    删除Character.create(之间的空格。

  2. :name的值包含尚未正确转义的嵌套单引号。你应该:

    name: 'Dr. Jonathan \'Jon\' Osterman'
    

    或双引号,%q{...}

  3. :bio值没有收尾报价。

答案 1 :(得分:-1)

name: 'Dr. Jonathan 'Jon' Osterman'行是一个破损的字符串。在实际错误之后,解析器错误出了名地跛行,然后抱怨一些无关的东西。试试name: "Dr. Jonathan 'Jon' Osterman"

然后正确格式化你的种子,有很多换行符,以帮助每个人看到正在发生的事情!