Complete Lesson 21

main
Simon Quigley 1 year ago
parent 41095dc0e3
commit 1a8d2c3e96

@ -0,0 +1,2 @@
class ReviewsController < ApplicationController
end

@ -0,0 +1,2 @@
module ReviewsHelper
end

@ -0,0 +1,3 @@
class Review < ApplicationRecord
belongs_to :movie
end

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :reviews
root "movies#index"
resources :movies

@ -0,0 +1,12 @@
class CreateReviews < ActiveRecord::Migration[7.0]
def change
create_table :reviews do |t|
t.string :name
t.integer :stars
t.text :comment
t.references :movie, null: false, foreign_key: true
t.timestamps
end
end
end

13
db/schema.rb generated

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_09_25_205851) do
ActiveRecord::Schema[7.0].define(version: 2023_09_26_165701) do
create_table "movies", force: :cascade do |t|
t.string "title"
t.string "rating"
@ -24,4 +24,15 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_25_205851) do
t.string "image_file_name"
end
create_table "reviews", force: :cascade do |t|
t.string "name"
t.integer "stars"
t.text "comment"
t.integer "movie_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["movie_id"], name: "index_reviews_on_movie_id"
end
add_foreign_key "reviews", "movies"
end

@ -0,0 +1,7 @@
require "test_helper"
class ReviewsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
stars: 1
comment: MyText
movie: one
two:
name: MyString
stars: 1
comment: MyText
movie: two

@ -0,0 +1,7 @@
require "test_helper"
class ReviewTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save