在 Rails 中创建新对象时出错

发布于 2024-09-24 18:40:23 字数 2280 浏览 4 评论 0原文

每当我尝试为模型创建对象时,我都会在 Rails 中收到此错误。我正在 Windows 7 上工作,

C:\Ruby\joker\chapter3>ruby script/console
Loading development environment (Rails 2.3.8)
>> mycb = ComicBook.new
SyntaxError: C:/Ruby/joker/chapter3/app/models/comic_book.rb:19: syntax error, u
nexpected $end, expecting kEND
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:380:in `load_without_new_constant_marking'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:380:in `load_file'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:521:in `new_constants_in'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:379:in `load_file'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:259:in `require_or_load'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:425:in `load_missing_constant'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:80:in `const_missing'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:92:in `const_missing'
        from (irb):1
>>

我还附加了图像,以便您可以查看模型本身

alt text

我也是附上您创建的模型漫画书

 C:\Ruby\joker\chapter3>ruby script/generate model ComicBook
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/comic_book.rb
      create  test/unit/comic_book_test.rb
      create  test/fixtures/comic_books.yml
      create  db/migrate
      create  db/migrate/20100923101842_create_comic_books.rb

我工作的环境是

Ruby version    1.8.7 (i386-mingw32)
RubyGems version    1.3.7
Rack version    1.1
Rails version   2.3.8
Active Record version   2.3.8
Active Resource version 2.3.8
Action Mailer version   2.3.8
Active Support version  2.3.8
Application root    C:/Ruby/joker/chapter3
Environment development
Database adapter    mysql
Database schema version 20100923101842

期待您的帮助

谢谢

I am getting this error in rails whenever i am trying to create an object for the model. I am working on Windows 7

C:\Ruby\joker\chapter3>ruby script/console
Loading development environment (Rails 2.3.8)
>> mycb = ComicBook.new
SyntaxError: C:/Ruby/joker/chapter3/app/models/comic_book.rb:19: syntax error, u
nexpected $end, expecting kEND
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:380:in `load_without_new_constant_marking'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:380:in `load_file'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:521:in `new_constants_in'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:379:in `load_file'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:259:in `require_or_load'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:425:in `load_missing_constant'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:80:in `const_missing'
        from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo
rt/dependencies.rb:92:in `const_missing'
        from (irb):1
>>

I have also attached the image so that you can look at the model itself

alt text

Also I am attaching you the created model ComicBook

 C:\Ruby\joker\chapter3>ruby script/generate model ComicBook
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/comic_book.rb
      create  test/unit/comic_book_test.rb
      create  test/fixtures/comic_books.yml
      create  db/migrate
      create  db/migrate/20100923101842_create_comic_books.rb

The environment I am working is

Ruby version    1.8.7 (i386-mingw32)
RubyGems version    1.3.7
Rack version    1.1
Rails version   2.3.8
Active Record version   2.3.8
Active Resource version 2.3.8
Action Mailer version   2.3.8
Active Support version  2.3.8
Application root    C:/Ruby/joker/chapter3
Environment development
Database adapter    mysql
Database schema version 20100923101842

Looking forward for your help

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掌心的温暖 2024-10-01 18:40:23

方法 self.upself.down 必须位于迁移 (db/migrate/20100923101842_create_comic_books.rb) 中,

CookBook 模型的 Clean 类必须如下所示:

class CookBook < ActiveRedord::Base
end

Methods self.up and self.down must be in the migration(db/migrate/20100923101842_create_comic_books.rb)

Clean class of the CookBook model must look like this:

class CookBook < ActiveRedord::Base
end
殊姿 2024-10-01 18:40:23

代码中缺少最后一个“结束”(models/comic_book.rb)

Last 'end' missing in your code (models/comic_book.rb)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文