javaherd/meal-planner — pull request #1 by javaherd (2014-12-13 06:02:04+00:00)
Title: Models test

In future I should certainly make PR's and commits into smaller chunks. The current state of this is simple. There are 2 accessible URLs, http://192.145.1.20:3000/meal_planner/create and http://192.145.1.20:3000/meal_planner/show

I created 3 models here: `Recipe`, `Ingredient`, and `RecipeIngredient`. (Follow `db/migrate/*` to see creation of the database). These models interact with a many to many relationship, and can be expanded upon with migrations in the future. The many-to-many relationship is not set up in the migrations where the database is set up - this is a very cool thing about rails, the relationship logic between the models is all done in the models and can be changed without redoing the whole db, see `app/models/*`.

There's also a seed file which seeds the db with initial recipies (By hand! it was so annoying! Should probably be using something like [this](https://github.com/rroblak/seed_dump) after we get a good page to populate the db)

The `create` action of the `meal_planner` (bad name for this controller) controller inserts a record using Rail's `form_for` which POSTs to the `recipes` controller (meals/app/controllers/recipes_controller.rb), which only updates the `Recipe` model currently. Next one will be to input ingredients and relations too. I plan on doing this by passing an array into the form using `form_fields` and creating the other records in the recipes controller. I'm not sure if it'll work or not.

I'm not sure if this is drivel, but I think some of it might be right.

Some cool pages I read:
http://guides.rubyonrails.org/migrations.html
Most of (`has_many :through`) http://guides.rubyonrails.org/association_basics.html