문제

I have an Item's Scaffold which has approximately 200+ Item's which are pre-fix.

So adding them manually is really painful.

Can i populate the Scaffold in my seed-file and then db:seed on production ?

I don't know the proper method but i think it's something like this:

items = Item.create([
    { name: 'css' }, 
    { name: 'css3' },
    { name: 'ruby' },
    { name: 'rails' },
    { name: 'python' },
    { name: 'html' }
    ])

I'm searching for a Solution that will seed my Item's Scaffold...

도움이 되었습니까?

해결책 2

You have to do it that way, but you don't need to asign it to the items variable.

You just have to add to the seed.rb file the code with your items. I've added the delete_all before to avoid creating duplicate items.

Item.delete_all
Item.create([
{ name: 'css' }, 
{ name: 'css3' },
{ name: 'ruby' },
{ name: 'rails' },
{ name: 'python' },
{ name: 'html' }
])

And then you'll have to seed your database with rake:db seed.

다른 팁

Try the following code by adding remaining items in array in db/seeds.rb file and run rake db:seed command. That generates expected records in items table.

['css','rubyonrails','java'].each do |item|

Item.find_or_create_by_name(:name => item)

end

Good luck.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top