0

Hi I am a beginner in ruby on rails platform and I'm going through the railstutorial.org book.My Micopost1.rb file content is

class Micropost1 < ActiveRecord::Base
  attr accessible :content, :user_id

belongs_to :user

validates :content, :length => { :maximum => 140 }

end

and when I run rails.console command then a console opens when I type in console first user.microposts then I getting following error log,

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'

I am not getting where I am wrong there are two models 1 is User and second is Micropost1 first I run this command for assigning variable first_user first_user=User.first please point me where I am mistaking.

3 Answers 3

3

attr accessible should be one word: attr_accessible

If you look down in your stacktrace, you'll see the following error:

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

This error is indicating that on line 2 of your micropost1.rb file, there is a method being called that does not exist.

Sign up to request clarification or add additional context in comments.

Comments

2

Try this...

class Micropost1 < ActiveRecord::Base
  attr_accessible :content, :user_id

  belongs_to :user

  validates :content, :length => { :maximum => 140 }

end

what you have written in your model is 'attr accessible', it is 'attr_accessible' like what written above...

2 Comments

Posting a code snippet without any explanation doesn't really help future visitors. It's useful to point out why you made the suggestion so that if someone stumbles on this question with a similar, but not exact issue, they'll have more info on how to fix it.
It's not a mistake, just something to improve upon. It's ok to be brief, but the more context you provide, the more helpful it will be for future visitors. Here's some other tips: stackoverflow.com/questions/how-to-answer
0

You should do some investigation, pretend that you are Sherlock Holmes!

Clue 1

SyntaxError: /home/ritesh/projects/demo/app/models/micropost1.rb:2: syntax error, unexpected tIDENTIFIER, expecting kEND

You know what kind of error you have, a syntax error. You have misspelled something.

Clue 2

If you look closely you can see that we have an other clue and that is the error tells you that it is in the model micropost1.rb:2 and :2 means it is in the second row in your code.

Clue 3

Okey, you know where the error is and what kind of error it is. But what does unexpected tIDENTIFIER, expecting kEND mean? Google is your watson. And he gives you 6 630 diffrent answers.

Case Closed

You found out that you have written in your model is 'attr accessible', instead it should be 'attr_accessible'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.