I'm currently in the process of creating a seeds file in my app and wanted to ensure that no duplicates were created using find_or_create_by
suggested in this post. I'm using find_or_create_by_name
but get this error:
NoMethodError: undefined method `find_or_create_by_name' for #<Class:0x007fa9680cb688>
This is what I'm using in the seeds file
Genre.find_or_create_by_name([
{name: "Alternative"},
{name: "Country"},
{name: "Electronic"}
])
Also worth asking. If I had a uniqueness validator for a model's name would find_or_create_by
still be necessary?