views:

29

answers:

1

I've got some strange behaviour going on with my DB Seed. the piece of code in question is this:

#seeding info about Question Types

@question_types = [:name=> "Single Input", :name=> "Multiple Choice"]

@question_types.each do |question_type|
  new_question_type = QuestionType.find_or_create_by_name(:name => question_type[:name]);
end

rake db:seed runs fine but when I look in the question_types table I find that only "Multiple Choice" has been created, no sign of "Single Input"

I tried deleting my DB and starting from scratch but it's still happening. I'm using Rails 2.3.5 and a PostgreSQL database

+2  A: 

Found it!

It was a syntax issue...

instead of:

@question_types = [:name=> "Single Input", :name=> "Multiple Choice"]

I needed:

@question_types = [{:name=> "Single Input"}, {:name=> "Multiple Choice"}]
Ganesh Shankar