Domanda

I am adding thousands of entries to my database through seeds.rb and a CSV file. In order to do so I am using Fast_Seeder:

FastSeeder.seed_csv!(Artist, "artist_sample.csv", :name, :sort_name)

I use Friendly-id, and as it is now, it is not creating a slug because I am not feeding it through the file. How do I go about creating it without having to change the file manually?

Any help would be much appreciated!

È stato utile?

Soluzione

I'm not familiar with Fast_Seeder, but I am with friendly-id. Their docs say the following:

# If you're adding FriendlyId to an existing app and need
# to generate slugs for existing users, do this from the
# console, runner, or add a Rake task:
User.find_each(&:save)

It would obviously be more efficient to get friendly-id playing nice in the first place, but barring that you can add that the next line. You basically just need to tap validation. I bet .find_each(&:valid?) might work too. This leads me to wonder if FastSeeder is creating these records without hitting your validations.

EDIT: Yup, I just dug through their source and they are creating straight through the database. You'll probably need to go the route I outlined above.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top