Marty Marty - 4 years ago 164
Ruby Question

Seeding fails upon `enum`

I have problems using

. I looked at the documentation but don't understand what I'm doing wrong (sorry, I'm a newbie). I my model file I have:

enum origin: [ :website, :stand, :other ]

In my seeds file I create a new record with one of the key-value pairs being
origin: "website"

content = Faker::Lorem.paragraphs(2)
author.articles.create!( title: "Title",
origin: "website",
content: content )

Upon seeding this generates the error:

ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: website is not a subclass of Article

What could be the cause of this error?

Update: I'm reading the same issue here: But I don't understand it. Could someone please explain?


class Article < ActiveRecord::Base
belongs_to :author
has_many :links
validates :author_id, presence: true

Answer Source

This should work:

author.articles.create!( title: "Title",
                         origin: :website,
                         content: content )

source for enums:

for an in-depth read about enums:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download