Reputation: 31
I'm following the Blog app from the RoR download site. The tutorial says enter this code to get some validation:
class Post < ActiveRecord::Base
validates :name, :presence => true
validates :title, :presence => true,
:length => { :minimum => 5 }
end
I've got this in my copy:
class Post < ActiveRecord::Base
validates :name, :presence => true,
validates :title, :presence => true,
:length => { :minimum => 5 }
end
Which, as far as I can see, is correct, however I get these error messages when I run the page:
c:/Sites/blog/app/models/post.rb:3: syntax error, unexpected tSYMBEG, expecting kDO or '{' or '('
validates :Title, :presence => true,
^
C:/Sites/blog/app/models/post.rb:3: Can't assign to true
C:/Sites/blog/app/models/post.rb:4: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
:length => { :minimum => 5 }
Can anyone point out what I've done wrong? It seems exactly the same to me.
Upvotes: 3
Views: 6801
Reputation: 1
I had the same error a while ago, and I put some attributes into the code so that it was fixed.
Your code must be like:
class Post < ActiveRecord::Base
attr_accessible :content, :name, :title
validates name, :presence => true
validates :title, :presence => true, length => { :minimum => 5 }
end
It worked for me.
Upvotes: 0
Reputation: 31
Be first indentation but I already ran well and if I worked anyway .. leave the code as I'm working.
Here is the code I use:
class Post < ActiveRecord::Base
validates:name, :presence=>true
validates:title,:presence=>true,
:length=>{:minimum=>5}
end
Upvotes: 3
Reputation: 2525
validates :name, :presence => true,
should be:
validates :name, :presence => true
(note the comma removed at the end)
Upvotes: 6
Reputation: 239311
You have a trailing comma on the line validates :name, :presence => true
.
Upvotes: 0
Reputation: 124419
You have a comma at the end of validates :name, :presence => true
in your post.rb
file; delete it.
Upvotes: 11