0

I'm building a web app where the user's need to choose from a database of exercises. They should be able to see the exercise name, description, and skill level. What is the best practice for building a database table for this purpose?

I'm thinking I could write each exercise and its attributes in a CSV file, then write a ruby script that would parse it and create an exercise object in the database table for each exercise that it parses. However, I have never done this before and would appreciate feedback.

And how would I migrate this database table from development to production on Heroku?

Thanks so much for any info.

4

2 回答 2

0

我最终创建了一个哈希数组并遍历了seeds.rb中的数组:

[
    { 
        :name         => "",
        :description  => "",
        :skill_level  => ""
    },
# Input more hashes below

].each do |exercise|
  ExerciseDb.create(
    name: exercise[:name]
    description: exercise[:description]
    skill_level: exercise[:skill_level]
  )
end
于 2013-06-26T17:27:44.310 回答
0

听起来像是一个带有名称、描述、技能水平和存储实际练习的东西的练习模型。由您决定是否要使用 csv 或 yaml 读取它 - 我同意 yaml 会更容易。还有如何存储用户的响应 - hstore、json、序列化 yaml...

于 2013-06-09T19:22:40.210 回答