Skip to content

Instantly share code, notes, and snippets.

@adeng21
Created April 22, 2014 21:24
Show Gist options
  • Select an option

  • Save adeng21/11194889 to your computer and use it in GitHub Desktop.

Select an option

Save adeng21/11194889 to your computer and use it in GitHub Desktop.
Seed file
category_attributes = [{name: 'Wrecks/Artifacts', image: Rails.root.join('/assets/images/categories/Wrecks.jpg')},
{name: 'Caves', image: Rails.root.join('/app/assets/images/categories/Caves.jpg')},
{name: 'Drift', image: Rails.root.join('/app/assets/images/categories/Drift.jpg')},
{name: 'Walls', image: Rails.root.join('/app/assets/images/categories/Walls.jpg')},
{name: 'Whales & Sharks', image: Rails.root.join('/app/assets/images/categories/Sharks.jpg')},
{name: 'Macro/Corals', image: Rails.root.join('/app/assets/images/categories/Corals.jpg')},
{name: 'Manta Rays', image:Rails.root.join('/app/assets/images/categories/Manta.jpg')},
{name: 'Night', image: Rails.root.join('/app/assets/images/categories/Night.jpg')},
{name: 'Turtles', image: Rails.root.join('/app/assets/images/categories/Turtles.jpg')},
{name: 'Schools of Fish', image: Rails.root.join('/app/assets/images/categories/Fish.jpg')}]
category_attributes.each do |attributes|
Category.create(attributes)
end
month_attributes = [{name: 'January'}, {name: 'February'},
{name: 'March'}, {name: 'April'}, {name: 'May'},
{name: 'June'}, {name: 'July'}, {name: 'August'},
{name: 'September'}, {name: 'October'}, {name: 'November'},
{name: 'December'}]
month_attributes.each do |attributes|
Month.create(attributes)
end
@wannabefro

Copy link
Copy Markdown

you want to do

category_attributes.each do |category|
  Category.find_or_create_by(category)
end

@wannabefro

Copy link
Copy Markdown

same with the months. use find or create by

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment