嗨,我是 rails 平台上的 ruby 初学者,我正在阅读 railstutorial.org 的书。我的 Micopost1.rb 文件内容是
class Micropost1 < ActiveRecord::Base
attr accessible :content, :user_id
belongs_to :user
validates :content, :length => { :maximum => 140 }
end
当我运行 rails.console 命令时,当我首先输入控制台 user.microposts 时会打开一个控制台,然后我会收到以下错误日志,
SyntaxError: /home/ritesh/projects/demo/app/models/micropost1.rb:2: syntax error, unexpected tIDENTIFIER, expecting kEND
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `load'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `load_file'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:468:in `load_file'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:353:in `require_or_load'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:514:in `load_missing_constant'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:219:in `constantize'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:218:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:218:in `constantize'
... 10 levels...
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:41
from script/rails:6:in `require'
from script/rails:6irb(main):004:0> first_user.micropost1s
NoMethodError: undefined method `accessible' for #<Class:0xb6651934>
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from /home/ritesh/projects/demo/app/models/micropost1.rb:2
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `load'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `load_file'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:468:in `load_file'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:353:in `require_or_load'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:514:in `load_missing_constant'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:192:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:190:in `const_missing'
from /var/lib/gems/1.8/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:219:in `constantize'
... 12 levels...
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
from /var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
from /usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:41
from script/rails:6:in `require'
我没有得到我错的地方有两个模型 1 是用户,第二个是 Micropost1 首先我运行这个命令来分配变量 first_user first_user=User.first 请指出我在哪里弄错了。