Compare commits

...

3 Commits

Author SHA1 Message Date
9b03bbd714 Complete Lesson 6 2023-09-25 13:41:38 -05:00
94f206d991 Complete Lesson 5 2023-09-25 13:41:38 -05:00
77465c4ab0 Complete Lesson 4 2023-09-25 13:41:32 -05:00
8 changed files with 68 additions and 5 deletions

View File

@ -1,8 +1,8 @@
class MoviesController < ApplicationController
def index
@choices, @movies = ["Iron Man ⎊", "Batman 🦇", "Forrest Gump 🏃"], []
(0..15).each{ |num|
@movies.append(@choices.sample())
}
@choices, @movies = Movie.all, []
(0..15).each{ |num|
@movies.append(@choices.sample())
}
end
end

2
app/models/movie.rb Normal file
View File

@ -0,0 +1,2 @@
class Movie < ApplicationRecord
end

View File

@ -5,7 +5,9 @@
<ul>
<% @movies.each do |movie| %>
<li><%= movie %></li>
<li><%= movie.title %> (<%= movie.rating %>, <%= movie.released_on %>): <%= number_to_currency(movie.total_gross, precision: 0) %>
<br /><i><%= movie.description %></i>
</li>
<% end %>
</ul>
</div>

View File

@ -0,0 +1,11 @@
class CreateMovies < ActiveRecord::Migration[7.0]
def change
create_table :movies do |t|
t.string :title
t.string :rating
t.decimal :total_gross
t.timestamps
end
end
end

View File

@ -0,0 +1,6 @@
class AddFieldsToMovies < ActiveRecord::Migration[7.0]
def change
add_column :movies, :description, :text
add_column :movies, :released_on, :date
end
end

24
db/schema.rb generated Normal file
View File

@ -0,0 +1,24 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_09_25_183426) do
create_table "movies", force: :cascade do |t|
t.string "title"
t.string "rating"
t.decimal "total_gross"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description"
t.date "released_on"
end
end

11
test/fixtures/movies.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
rating: MyString
total_gross: 9.99
two:
title: MyString
rating: MyString
total_gross: 9.99

View File

@ -0,0 +1,7 @@
require "test_helper"
class MovieTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end