jeffp / enumerated_attribute

Easy enum for your models, objects and views
MIT License
190 stars 64 forks source link

#to_xml only works when record loaded from database #37

Open tilsammans opened 12 years ago

tilsammans commented 12 years ago

Calling #to_xml on a record with enumerated_attribute results in an error when the record is created and still in memory. The error disappears when the record is loaded from the database.

class Post
  enumerated_attribute :kind, %w(post page)
end

This fails:

post = Post.create! name: 'First post'
post.to_xml

This works:

Post.create! name: 'Second post'
post = Post.find_by_name 'Second post'
post.to_xml