Railstutorial 6.1.3

时间:2015-07-10 22:36:51

标签: ruby-on-rails

我遇到了一个问题:当我在rails控制台--sandbox中输入User.new时,它没有给出教程预期的结果。它只是提供了一堆我不理解的文本。我已经完成了教程中的所有其他内容,并且能够跟进,直到现在。我不知道为什么这不起作用。

ps:user.rb仅包含:

class User < ActiveRecord::Base end

这是教程显示的内容。

from -e:1:in `<main>'>> User.new
SyntaxError: /home/ubuntu/workspace/sample_app/app/models/user.rb:2: syntax error, unexpected keyword_end, expecting end-of-input
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:457:in `block in load_file'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:647:in `new_constants_in'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:456:in `load_file'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:354:in `require_or_load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:494:in `load_missing_constant'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:184:in `const_missing'
        from (irb):9
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/console.rb:110:in `start'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/console.rb:9:in `start'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `block in require'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
        from /home/ubuntu/workspace/sample_app/bin/rails:8:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

1 个答案:

答案 0 :(得分:0)

改变这个:

class User < ActiveRecord::Base end

对此:

class User < ActiveRecord::Base; end

或者这个:

class User < ActiveRecord::Base
end

Ruby希望类名和end之间有一个语句分隔符;换行或分号都可以使用。