In the migration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Some other methods:
find_each method: look it up in guides here. find_each yields each individual object one at a time find_in_batches it yields songs
in the seeds file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
This will output the log output of the rake tasks:
update the forms in the application (2:50)
Shortcut: cmd D shortcut to highlight similar words to edit
errors: when you get a stack trace and it’s part of rails you can ignore it because you created the file NOT rails.
(2:58) artists have many albums through their songs - a many to many association
if a model has 2 :belongs_to associations means that it is a join table even though it is a join model is has all the same behaviors as a has_many assoc
INNER JOIN is SQL: The INNER JOIN keyword return rows when there is at least one match in both tables.
Foreign Key/ belongs_to RULE
if it belongs_to xyz it is a foreign key. if it is a foreign key than it belongs_to xyz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
How do we build forms that give users the same abilities we have through forms? If a field name end in an , it will allow multiple fields and rails will treat it as unique values and glob them together in a params array (4:46) - If you want to have multiple fields anem it with an empty array
in the mixtapes_controller
1 2 3 4 5 6
Next level of abstraction up… (4:55) in the html we want to pass in: mixtape[song_ids]
??Mass assignment is this accordian of ____ a writer method implies an attribute of a model Main goal as a programmer name your data so that it is easily accessbile in params
TODO (5:03) HTML: scope, attribute, attribute kind
NEXT: A rails implementation: form_tag helper, a low level rails helper all these methods do is generate html for you. not all that railsy.
At least we aren’t writing HTML here now… this level of implementation gives you lots of flexibility and control but at the expense of maintainability and explicitness.
form helper builders
html, form_tag helpers family, form helpers in order of low level of abstraction to higher want to bind the active record object to the form element e.g. text_field, label (5:17)
We want to bind the instance var to the form itself - the problem with text_field is that hte form is still built without any knowledge of the active record instance behind the form –> it should be an extension of the object - these are the way our scaffolds normally work
form_for method yields a form builderthat knows the model the form is about
mixtape_form.object would return the mixtape object because it has knowledge of the form object
you also get access to fields_for -
1 2 3 4 5
Does your model implement a method called “mixtape_songs_attributes=”
1 2 3 4 5 6 7 8 9 10 11 12 13 14
an attribute has a getter and setter method called the name of the attribute
Rails Casts on this subject: Many to Many