http://www.sw.it.aoyama.ac.jp/2019/Projects2/lecture10.html
© 2019 Martin J. Dürst 青山学院大学
.json extension)Accept: application/json HTTP header) of the application and
dowloads dataActor and Moviehas_and_belongs_to_many :movies (in the Actor
model) andhas_and_belongs_to_many :actors (in the Movie
model)actors_movies in the case of actors and movies, with columns
actor_id and movie_id)posts with comments (each post
has many comments, but each comment belongs to exactly one post)belongs_to :post (singular!)has_many :comments (plural!)post_id (integer) on the many side
(comments)posts) does not need an additional
column:post_id column on
comments, which is against database rules@post.comments (array, plural!)@comment.post (singular!)/posts/23/comments/45)add_column,
remove_column)rails generate migration
MigrationNamedb/migrate20190617010324_add_points_to_reviews.rb)rails db:migrate will execute all pending migrationsrails db:rollback
parametersrails
db:migrate:statusclass AddPointsToReviews <
ActiveRecord::Migration[5.2])ActiveRecord::Migration5.2 indicates the version of the migration
library/DSLchange methodchange method indicate what has to
be changedadd_column)add_column actually works as remove_column
when rolling back a migration)new and edit actions_name.html.erb)render 'name' in the
viewcinema.scaffold for movies. Each movie has a
title (string), a description
(text).scaffold for reviews. Each review has
a content (text) and a reference to the movie
being reviewed (movie_id, integer).foreign_key:
true to the relevant field.rails db:migrate.10aCinema.sqlite3 and
submit it to Moodle (deadline 17:00).show and
index, display the movie title instead of the movie number.
Make sure you also adjust the labels/legends.10bShow.html.erb and
10bIndex.html.erb, and submit them to Moodle (deadline
17:30).index view of the
reviews.10cShow.html.erb and submit it to
Moodle (deadline 17:50).AddPointsToReviews.points column to
the reviews table, with type integer.rails db:migrate.points
parameter._form.html.erb._form.html.erb to 10d_form.html.erb. Copy the
reviews controller to 10dReviewsController.rb. Copy
movies/show.html.erb to 10dMoviesShow.html.erb.
Copy reviews/index.html.erb to
10dReviewsIndex.html.erb (deadline 18:30).(no need to submit)