Skip to content

Rails 4: Role.find_or_create_by_name in db/seeds.rb #40

@peteforde

Description

@peteforde

The example seed file suggested fails under Rails 4 RC1 with the following error and a stack trace:

Could not find table 'name'

I converted:

Role.find_or_create_by_name({ :name => role }, :without_protection => true)

to:

Role.where(:name => role).first_or_create(:without_protection => true)

Now it seems to work great.

Note that I did switch from find_or_create to first_or_create, which seemed more explicit for this context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions