This repo includes seedfiles, creating an entity-relationship-diagram, using form_for and form_tag with drop downs and checkboxes referencing other models.
You can prepopulate your database by adding code to your seeds.rb
file.
Just run $ rake db:seed
If you want to seed your database on heroku run
$ heroku run rake db:seed
$ rake erd
will generate a PDF in your app directory of your models relationships.
Be sure to run $ brew install graphviz
first.
Creating a form by hand will result in a params like the following:
params = {name: "Harry Potter", age: 12, id: 1, action: 'create', controller: 'students'}
And in your controller
Student.new(name: params[:name], age: params[:age])
form_for
can render an HTML form for a specific model. This means your params will contain a hash representing that object.
params = {student: { name: "Harry Potter", age: 12 }, id: 1, action: 'create', controller: 'students'}
And in your controller
Student.new(params[:student])
You can pass the entire student hash in to create a new object in your controller
Check out the new student form for a select box drop down of houses. Check out the edit student page for check boxes of all the students spells.