I am very new to Ruby on Rails and I was following the Railstutorial to make a demo app using Scaffold.
First when I added the User model using scaffold, it worked fine. Then, when I added the micropost model, I kept getting the following error:
/demo_app/app/models/micropost.rb:4: syntax error, unexpected ':', expecting keyword_end
belongs_to: user
I noticed that the code generated by scaffold did not generate the same code as shown in the tutorial. Here is the User and Microposts model :
class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :microposts
end
class Micropost < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to: user
validates :content, :length => { :maximum => 140 }
end
The attr_accessible line is not there in the tutorial. what is this exactly and is this the problem?
I have run the Rake program and everything else that was mentioned.
It should be
belongs_to :user. You better use some texteditor with highlight for rails