This one really has me. I have this validation in my user model:
validates :first_class, :presence => true, :inclusion => %w(Fighter Ranger Magician)
Now, I try an example create in my console:
ruby-1.9.2-p180 :053 > new = User.create(:first_class => 'Magician')
=> #<User id: nil, ...
ruby-1.9.2-p180 :054 > new.errors
=> {:first_class=>["can't be blank", "is not included in the list"]}
Why am I getting this validation error? I SERIOUSLY cannot figure that out.
(If i remove the validation, the user gets created, but first_class is nil :O)
maybe try having
attr_accessible :first_classin your model fileYou have to tell rails which attributes are writeable through mass-assignment. The
newmethod takes a parameters hash, which is considered mass-assignment. The same is true withupdate_attributes.To verify, you could just make a new instance and say
object.first_class = 'Magician'. If this also fails, then you knowattr_accessibleis not the problem.